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
impl AesGcmCrypter
Source§impl AesGcmCrypter
impl AesGcmCrypter
Sourcepub fn encrypt_with_aad(
&self,
plaintext: &[u8],
aad: &[u8],
) -> Result<Vec<u8>, CryptoError>
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 才能成功。
Sourcepub fn decrypt_with_aad(
&self,
ciphertext: &[u8],
aad: &[u8],
) -> Result<Vec<u8>, CryptoError>
pub fn decrypt_with_aad( &self, ciphertext: &[u8], aad: &[u8], ) -> Result<Vec<u8>, CryptoError>
AES-GCM 认证解密(带附加认证数据 AAD)
必须提供与加密时相同的 AAD,否则认证标签校验失败。
Trait Implementations§
Auto Trait Implementations§
impl Freeze for AesGcmCrypter
impl RefUnwindSafe for AesGcmCrypter
impl Send for AesGcmCrypter
impl Sync for AesGcmCrypter
impl Unpin for AesGcmCrypter
impl UnsafeUnpin for AesGcmCrypter
impl UnwindSafe for AesGcmCrypter
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