[][src]Struct devolutions_crypto::ciphertext::Ciphertext

pub struct Ciphertext { /* fields omitted */ }

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]

Decrypt the data blob using a PrivateKey.

Arguments

  • private_key - Key to use. Must be the one in the same keypair as the PublicKey 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);

Trait Implementations

impl Clone for Ciphertext[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

impl<'_> TryFrom<&'_ [u8]> for Ciphertext[src]

type Error = Error

The type returned in the event of a conversion error.

fn try_from(data: &[u8]) -> Result<Self, Error>[src]

Parses the data. Can return an Error of the data is invalid or unrecognized.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,