Skip to main content

AesGcmCrypter

Struct AesGcmCrypter 

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

AES-256-GCM 加密器(密码学安全)

使用 AES-256-GCM AEAD 算法,每次加密生成随机 12 字节 nonce。 密文格式:nonce(12) || ciphertext || tag(16)(由 aes-gcm crate 内部处理)。

Implementations§

Source§

impl AesGcmCrypter

Source

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

从 32 字节密钥创建

Source

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

从任意长度密钥字符串创建(SHA-256 派生 32 字节密钥)

Source§

impl AesGcmCrypter

Source

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

AES-GCM 认证加密(带附加认证数据 AAD)

密文格式:nonce(12) || ciphertext || tag(16) AAD(Additional Authenticated Data)不包含在密文中,但参与认证标签计算, 解密时必须提供相同的 AAD 才能成功。

Source

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

AES-GCM 认证解密(带附加认证数据 AAD)

必须提供与加密时相同的 AAD,否则认证标签校验失败。

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