lockaes_gcm_encrypt

On-chain AES-256-GCM encryption

Encrypt bytes with the AES-GCM precompile at 0x66.

Overview

aes_gcm_encrypt() and async_aes_gcm_encrypt() accept a 32-byte key, a 12-byte nonce (or nonce integer), and plaintext bytes.

The returned ciphertext includes the 16-byte authentication tag.

Signature

def aes_gcm_encrypt(
    w3: Web3,
    *,
    aes_key: Bytes32,
    nonce: int | EncryptionNonce,
    plaintext: bytes,
) -> HexBytes

async def async_aes_gcm_encrypt(
    w3: AsyncWeb3,
    *,
    aes_key: Bytes32,
    nonce: int | EncryptionNonce,
    plaintext: bytes,
) -> HexBytes

Parameters

Parameter
Type
Required
Description

w3

Web3 / AsyncWeb3

Yes

Connected Seismic client

aes_key

Yes

32-byte AES key

nonce

Yes

12-byte nonce (or int converted to 12-byte big-endian)

plaintext

bytes

Yes

Data to encrypt

Returns

Type
Description

HexBytes

Ciphertext with authentication tag appended

Examples

Basic Usage

With EncryptionNonce

Async Usage

Encrypt/Decrypt Round Trip

Gas Cost

The SDK uses:

Examples:

  • len(plaintext)=0: 1000

  • len(plaintext)=16: 1030

  • len(plaintext)=17: 1060

Notes

  • Never reuse a nonce with the same key.

  • int nonces are encoded to 12-byte big-endian values.

  • Returned bytes are ciphertext || tag.

See Also

Last updated