Struct openssl::encrypt::Encrypter

source ·
pub struct Encrypter<'a> { /* private fields */ }
Expand description

A type which encrypts data.

Implementations§

source§

impl<'a> Encrypter<'a>

source

pub fn new<T>(pkey: &'a PKeyRef<T>) -> Result<Encrypter<'a>, ErrorStack>where T: HasPublic,

Creates a new Encrypter.

OpenSSL documentation at EVP_PKEY_encrypt_init.

source

pub fn rsa_padding(&self) -> Result<Padding, ErrorStack>

Returns the RSA padding mode in use.

This is only useful for RSA keys.

This corresponds to EVP_PKEY_CTX_get_rsa_padding.

source

pub fn set_rsa_padding(&mut self, padding: Padding) -> Result<(), ErrorStack>

Sets the RSA padding mode.

This is only useful for RSA keys.

This corresponds to EVP_PKEY_CTX_set_rsa_padding.

source

pub fn set_rsa_mgf1_md(&mut self, md: MessageDigest) -> Result<(), ErrorStack>

Sets the RSA MGF1 algorithm.

This is only useful for RSA keys.

This corresponds to EVP_PKEY_CTX_set_rsa_mgf1_md.

source

pub fn set_rsa_oaep_md(&mut self, md: MessageDigest) -> Result<(), ErrorStack>

Sets the RSA OAEP algorithm.

This is only useful for RSA keys.

This corresponds to EVP_PKEY_CTX_set_rsa_oaep_md.

source

pub fn set_rsa_oaep_label(&mut self, label: &[u8]) -> Result<(), ErrorStack>

Sets the RSA OAEP label.

This is only useful for RSA keys.

This corresponds to EVP_PKEY_CTX_set0_rsa_oaep_label.

source

pub fn encrypt(&self, from: &[u8], to: &mut [u8]) -> Result<usize, ErrorStack>

Performs public key encryption.

In order to know the size needed for the output buffer, use encrypt_len. Note that the length of the output buffer can be greater of the length of the encoded data.

let mut encrypter = Encrypter::new(&pkey).unwrap();
encrypter.set_rsa_padding(Padding::PKCS1).unwrap();

// Get the length of the output buffer
let buffer_len = encrypter.encrypt_len(&input).unwrap();
let mut encoded = vec![0u8; buffer_len];

// Encode the data and get its length
let encoded_len = encrypter.encrypt(&input, &mut encoded).unwrap();

// Use only the part of the buffer with the encoded data
let encoded = &encoded[..encoded_len];

This corresponds to EVP_PKEY_encrypt.

source

pub fn encrypt_len(&self, from: &[u8]) -> Result<usize, ErrorStack>

Gets the size of the buffer needed to encrypt the input data.

This corresponds to EVP_PKEY_encrypt called with a null pointer as output argument.

Trait Implementations§

source§

impl<'a> Drop for Encrypter<'a>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<'a> Send for Encrypter<'a>

source§

impl<'a> Sync for Encrypter<'a>

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for Encrypter<'a>

§

impl<'a> Unpin for Encrypter<'a>

§

impl<'a> UnwindSafe for Encrypter<'a>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.