pub trait Encrypter {
// Required method
fn encapsulation_public_key(&self) -> EncapsulationPublicKey;
// Provided method
fn encapsulate_new_shared_secret(
&self,
) -> (SymmetricKey, EncapsulationCiphertext) { ... }
}Expand description
A trait for types that can encapsulate shared secrets for public key encryption.
The Encrypter trait defines an interface for encapsulating a shared secret
using a public key. This is a key part of hybrid encryption schemes, where a
shared symmetric key is encapsulated with a public key, and the recipient
uses their private key to recover the symmetric key.
Types implementing this trait provide the ability to:
- Access their encapsulation public key
- Generate and encapsulate new shared secrets
This trait is typically implemented by:
- Encapsulation public keys
- Higher-level types that contain or can generate encapsulation public keys
Required Methods§
Sourcefn encapsulation_public_key(&self) -> EncapsulationPublicKey
fn encapsulation_public_key(&self) -> EncapsulationPublicKey
Returns the encapsulation public key for this encrypter.
§Returns
The encapsulation public key that should be used for encapsulation.
Provided Methods§
Encapsulates a new shared secret for the recipient.
This method generates a new shared secret and encapsulates it using the encapsulation public key from this encrypter.
§Returns
A tuple containing:
- The generated shared secret as a
SymmetricKey - The encapsulation ciphertext that can be sent to the recipient
§Example
use bc_components::{EncapsulationScheme, Encrypter};
// Generate a recipient keypair
let (recipient_private_key, recipient_public_key) =
EncapsulationScheme::default().keypair();
// Encapsulate a new shared secret
let (shared_secret, ciphertext) =
recipient_public_key.encapsulate_new_shared_secret();Implementors§
impl Encrypter for EncapsulationPublicKey
Implementation of the Encrypter trait for EncapsulationPublicKey.
This allows EncapsulationPublicKey to be used with the generic encryption
interface defined by the Encrypter trait.
impl Encrypter for PublicKeys
impl Encrypter for X25519PublicKey
Implements the Encrypter trait to support key encapsulation mechanisms.