[−][src]Function devolutions_crypto::ciphertext::encrypt_asymmetric
pub fn encrypt_asymmetric(
data: &[u8],
public_key: &PublicKey,
version: CiphertextVersion
) -> Result<Ciphertext, Error>
Returns an Ciphertext from cleartext data and a PublicKey.
You will need the corresponding PrivateKey to decrypt it.
Arguments
data- The data to encrypt.public_key- ThePublicKeyto use. Use eithergenerate_keypairorderive_keypairto generate a keypair.version- Version of the library to encrypt with. UseCiphertTextVersion::Latestif you're not dealing with shared data.
Returns
Returns a Ciphertext containing the encrypted data.
Example
use devolutions_crypto::ciphertext::{ encrypt_asymmetric, CiphertextVersion }; use devolutions_crypto::key::{ generate_keypair, KeyVersion }; let data = b"somesecretdata"; let keypair = generate_keypair(KeyVersion::Latest); let encrypted_data = encrypt_asymmetric(data, &keypair.public_key, CiphertextVersion::Latest).unwrap();