pub struct Ciphertext { /* private fields */ }
Expand description
A versionned ciphertext. Can be either symmetric or asymmetric.
Implementations§
Source§impl Ciphertext
impl Ciphertext
Sourcepub fn decrypt(&self, key: &[u8]) -> Result<Vec<u8>>
pub fn decrypt(&self, key: &[u8]) -> Result<Vec<u8>>
Decrypt the data blob using a key.
§Arguments
key
- Key to use. The recommended size is 32 bytes.
§Returns
Returns the decrypted data.
§Example
use devolutions_crypto::ciphertext::{ encrypt, CiphertextVersion};
let data = b"somesecretdata";
let key = b"somesecretkey";
let encrypted_data = encrypt(data, key, CiphertextVersion::Latest).unwrap();
let decrypted_data = encrypted_data.decrypt(key).unwrap();
assert_eq!(data.to_vec(), decrypted_data);
Sourcepub fn decrypt_with_aad(&self, key: &[u8], aad: &[u8]) -> Result<Vec<u8>>
pub fn decrypt_with_aad(&self, key: &[u8], aad: &[u8]) -> Result<Vec<u8>>
Decrypt the data blob using a key.
§Arguments
key
- Key to use. The recommended size is 32 bytes.aad
- Additionnal data to authenticate alongside the ciphertext.
§Returns
Returns the decrypted data.
§Example
use devolutions_crypto::ciphertext::{ encrypt_with_aad, CiphertextVersion};
let data = b"somesecretdata";
let key = b"somesecretkey";
let aad = b"somepublicdata";
let encrypted_data = encrypt_with_aad(data, key, aad, CiphertextVersion::Latest).unwrap();
let decrypted_data = encrypted_data.decrypt_with_aad(key, aad).unwrap();
assert_eq!(data.to_vec(), decrypted_data);
Sourcepub fn decrypt_asymmetric(&self, private_key: &PrivateKey) -> Result<Vec<u8>>
pub fn decrypt_asymmetric(&self, private_key: &PrivateKey) -> Result<Vec<u8>>
Decrypt the data blob using a PrivateKey
.
§Arguments
private_key
- Key to use. Must be the one in the same keypair as thePublicKey
used for encryption.
§Returns
Returns the decrypted 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();
let decrypted_data = encrypted_data.decrypt_asymmetric(&keypair.private_key).unwrap();
assert_eq!(decrypted_data, data);
Sourcepub fn decrypt_asymmetric_with_aad(
&self,
private_key: &PrivateKey,
aad: &[u8],
) -> Result<Vec<u8>>
pub fn decrypt_asymmetric_with_aad( &self, private_key: &PrivateKey, aad: &[u8], ) -> Result<Vec<u8>>
Decrypt the data blob using a PrivateKey
.
§Arguments
private_key
- Key to use. Must be the one in the same keypair as thePublicKey
used for encryption.aad
- Additionnal data to authenticate alongside the ciphertext.
§Returns
Returns the decrypted data.
§Example
use devolutions_crypto::ciphertext::{ encrypt_asymmetric_with_aad, CiphertextVersion };
use devolutions_crypto::key::{ generate_keypair, KeyVersion };
let data = b"somesecretdata";
let keypair = generate_keypair(KeyVersion::Latest);
let aad = b"somepublicdata";
let encrypted_data = encrypt_asymmetric_with_aad(data, &keypair.public_key, aad, CiphertextVersion::Latest).unwrap();
let decrypted_data = encrypted_data.decrypt_asymmetric_with_aad(&keypair.private_key, aad).unwrap();
assert_eq!(decrypted_data, data);
Trait Implementations§
Source§impl Clone for Ciphertext
impl Clone for Ciphertext
Source§fn clone(&self) -> Ciphertext
fn clone(&self) -> Ciphertext
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for Ciphertext
impl Debug for Ciphertext
Source§impl From<Ciphertext> for Vec<u8>
impl From<Ciphertext> for Vec<u8>
Source§fn from(data: Ciphertext) -> Self
fn from(data: Ciphertext) -> Self
Serialize the structure into a Vec<u8>
, for storage, transmission or use in another language.
Source§impl HeaderType for Ciphertext
impl HeaderType for Ciphertext
Auto Trait Implementations§
impl Freeze for Ciphertext
impl RefUnwindSafe for Ciphertext
impl Send for Ciphertext
impl Sync for Ciphertext
impl Unpin for Ciphertext
impl UnwindSafe for Ciphertext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more