encrypt_asymmetric

Function encrypt_asymmetric 

Source
pub fn encrypt_asymmetric(
    data: &[u8],
    public_key: &PublicKey,
    version: CiphertextVersion,
) -> Result<Ciphertext>
Expand description

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 - The PublicKey to use. Use generate_keypair to generate a keypair.
  • version - Version of the library to encrypt with. Use CiphertTextVersion::Latest if 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();