[−][src]Struct devolutions_crypto::ciphertext::Ciphertext
A versionned ciphertext. Can be either symmetric or asymmetric.
Methods
impl Ciphertext[src]
pub fn decrypt(&self, key: &[u8]) -> Result<Vec<u8>, Error>[src]
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);
pub fn decrypt_asymmetric(
&self,
private_key: &PrivateKey
) -> Result<Vec<u8>, Error>[src]
&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
impl Clone for Ciphertext[src]
fn clone(&self) -> Ciphertext[src]
fn clone_from(&mut self, source: &Self)1.0.0[src]
impl Debug for Ciphertext[src]
impl From<Ciphertext> for Vec<u8>[src]
fn from(data: Ciphertext) -> Self[src]
Serialize the structure into a Vec<u8>, for storage, transmission or use in another language.
impl HeaderType for Ciphertext[src]
type Version = CiphertextVersion
type Subtype = CiphertextSubtype
fn data_type() -> DataType[src]
fn default_version() -> Self::Version[src]
fn subtype() -> Self::Subtype[src]
impl<'_> TryFrom<&'_ [u8]> for Ciphertext[src]
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
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone, [src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T[src]
fn clone_into(&self, target: &mut T)[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,