Skip to main content

PublicKeyEncryption

Trait PublicKeyEncryption 

Source
pub trait PublicKeyEncryption {
    type PublicKey;
    type SecretKey;

    // Required methods
    fn keygen(bits: usize) -> (Self::PublicKey, Self::SecretKey);
    fn encrypt(pk: &Self::PublicKey, plaintext: &[u8]) -> Vec<u8> ;
    fn decrypt(sk: &Self::SecretKey, ciphertext: &[u8]) -> Option<Vec<u8>>;
}
Expand description

Trait for public-key encryption schemes.

Like SignatureScheme, this trait is currently informational – the RSA encryption helpers in rsa::pkcs1 and rsa::oaep take a parameter of type rsa::rsa::RsaPublicKey / RsaSecretKey directly rather than going through this trait, because OAEP and PKCS#1 v1.5 each take additional protocol parameters (label, RNG) that don’t fit the simple shape below.

Required Associated Types§

Source

type PublicKey

Public key type.

Source

type SecretKey

Secret key type.

Required Methods§

Source

fn keygen(bits: usize) -> (Self::PublicKey, Self::SecretKey)

Generate a key pair of the given bit size.

Source

fn encrypt(pk: &Self::PublicKey, plaintext: &[u8]) -> Vec<u8>

Encrypt a plaintext under the public key.

Source

fn decrypt(sk: &Self::SecretKey, ciphertext: &[u8]) -> Option<Vec<u8>>

Decrypt a ciphertext with the secret key. Returns None if the padding does not validate.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§