Struct devolutions_crypto::ciphertext::Ciphertext
source · 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>, Error>
pub fn decrypt(&self, key: &[u8]) -> Result<Vec<u8>, Error>
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_asymmetric(
&self,
private_key: &PrivateKey
) -> Result<Vec<u8>, Error>
pub fn decrypt_asymmetric( &self, private_key: &PrivateKey ) -> Result<Vec<u8>, Error>
Decrypt the data blob using a PrivateKey.
Arguments
private_key- Key to use. Must be the one in the same keypair as thePublicKeyused 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);Trait Implementations§
source§impl Clone for Ciphertext
impl Clone for Ciphertext
source§fn clone(&self) -> Ciphertext
fn clone(&self) -> Ciphertext
Returns a copy 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 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