Polkadot Apps
    Preparing search index...
    • 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.

      Parameters

      • data: Uint8Array

        Binary data to encrypt.

      • key: Uint8Array

        32-byte AES-256 key.

      Returns { ciphertext: Uint8Array; nonce: Uint8Array }

      Object containing the ciphertext and the random nonce used.

      If key is not exactly 32 bytes.

      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);