Skip to main content

AesGcmCrypter

Struct AesGcmCrypter 

Source
pub struct AesGcmCrypter { /* private fields */ }
Expand description

AES-256-GCM crypter (cryptographically secure).

Uses the AES-256-GCM AEAD algorithm and generates a random 12-byte nonce on each encryption. Ciphertext format: nonce(12) || ciphertext || tag(16) (handled internally by the aes-gcm crate).

Implementations§

Source§

impl AesGcmCrypter

Source

pub fn new(key: &[u8; 32]) -> Self

Create from a 32-byte key.

Source

pub fn from_key_str(key: &str) -> Self

Create from a key string of arbitrary length (derives a 32-byte key via SHA-256).

Source§

impl AesGcmCrypter

Source

pub fn encrypt_with_aad( &self, plaintext: &[u8], aad: &[u8], ) -> Result<Vec<u8>, CryptoError>

AES-GCM authenticated encryption (with Additional Authenticated Data, AAD).

Ciphertext format: nonce(12) || ciphertext || tag(16). AAD (Additional Authenticated Data) is not included in the ciphertext but participates in the authentication tag computation; the same AAD must be provided during decryption to succeed.

Source

pub fn decrypt_with_aad( &self, ciphertext: &[u8], aad: &[u8], ) -> Result<Vec<u8>, CryptoError>

AES-GCM authenticated decryption (with Additional Authenticated Data, AAD).

The same AAD used during encryption must be provided, otherwise the authentication tag verification fails.

Trait Implementations§

Source§

impl Crypter for AesGcmCrypter

Source§

fn encrypt(&self, plaintext: &[u8]) -> Result<Vec<u8>, CryptoError>

Source§

fn decrypt(&self, ciphertext: &[u8]) -> Result<Vec<u8>, CryptoError>

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

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

Source§

fn vzip(self) -> V