Skip to main content

aes_gcm_encrypt

Function aes_gcm_encrypt 

Source
pub fn aes_gcm_encrypt<'py>(
    py: Python<'py>,
    key: &[u8],
    nonce: &[u8],
    plaintext: &[u8],
    aad: Option<&[u8]>,
) -> PyResult<Bound<'py, PyBytes>>
Expand description

Encrypt data using AES-GCM (authenticated encryption with associated data).

Key length determines the AES variant: 16 → AES-128, 24 → AES-192, 32 → AES-256. nonce must be exactly 12 bytes.

Returns ciphertext ‖ tag where the authentication tag is 16 bytes. aad (additional authenticated data) is authenticated but not encrypted; pass an empty :class:bytes object when no AAD is needed.

The output format is identical to cryptography.hazmat.primitives.ciphers.aead.AESGCM(key).encrypt(nonce, plaintext, aad).

import synta.crypto as sc, os

key   = os.urandom(32)
nonce = os.urandom(12)
ct    = sc.aes_gcm_encrypt(key, nonce, b"hello", b"extra-data")