Skip to main content

decrypt

Function decrypt 

Source
pub fn decrypt(
    key: &[u8; 32],
    nonce: &[u8; 12],
    ciphertext: &[u8],
    aad: &[u8],
) -> Result<Vec<u8>>
Expand description

Decrypt data using ChaCha20-Poly1305 (AEAD)

§Arguments

  • key - 32-byte encryption key (same as used for encryption)
  • nonce - 12-byte nonce (same as used for encryption)
  • ciphertext - Encrypted data with authentication tag
  • aad - Additional authenticated data (must match encryption)

§Returns

Decrypted plaintext

§Errors

Returns AionError::DecryptionFailed if:

  • Authentication tag is invalid (data was tampered with)
  • Wrong key or nonce used
  • AAD doesn’t match