Encrypt binary data with AES-256-GCM.
Generates a random 12-byte nonce and returns it alongside the ciphertext. The ciphertext includes the 16-byte authentication tag appended by GCM.
Binary data to encrypt.
32-byte AES-256 key.
Object containing the ciphertext and the random nonce used.
ciphertext
nonce
If key is not exactly 32 bytes.
key
import { aesGcmEncrypt, aesGcmDecrypt } from "@polkadot-apps/crypto";import { randomBytes } from "@polkadot-apps/crypto";const key = randomBytes(32);const { ciphertext, nonce } = aesGcmEncrypt(data, key);const plaintext = aesGcmDecrypt(ciphertext, key, nonce); Copy
import { aesGcmEncrypt, aesGcmDecrypt } from "@polkadot-apps/crypto";import { randomBytes } from "@polkadot-apps/crypto";const key = randomBytes(32);const { ciphertext, nonce } = aesGcmEncrypt(data, key);const plaintext = aesGcmDecrypt(ciphertext, key, nonce);
Encrypt binary data with AES-256-GCM.
Generates a random 12-byte nonce and returns it alongside the ciphertext. The ciphertext includes the 16-byte authentication tag appended by GCM.