Aes Gcm¶
Import: import system.crypto;
AesGcm¶
AES-256-GCM authenticated encryption (confidentiality + integrity). Host-backed via the aes-gcm crate natively and Web Crypto / node:crypto in the browser/Node hosts.
nonce_size¶
Standard 96-bit (12-byte) GCM nonce size.
tag_size¶
128-bit (16-byte) authentication tag appended to every ciphertext.
generate_nonce¶
Generates a fresh random 12-byte nonce. Never reuse a nonce with the same key.
encrypt¶
Encrypts plaintext under key/nonce, authenticating aad (additional authenticated data, not encrypted but tamper-checked) alongside it. Returns ciphertext with a 16-byte authentication tag appended. nonce must be exactly nonce_size bytes and must never be reused with the same key.
public static fun encrypt(
key: AesGcmKey,
nonce: byte[],
plaintext: byte[],
aad: byte[]
): Result<byte[], CryptoError>
decrypt¶
Decrypts and authenticates ciphertext (as produced by encrypt, tag included) under key/nonce/aad. Returns an error if the nonce length is wrong or authentication fails (tampered ciphertext, wrong key/nonce/aad, or truncated input).