Polkadot Apps
    Preparing search index...
    • NaCl box encrypt: authenticated encryption where both sender and recipient are known.

      Uses X25519 for key agreement and XSalsa20-Poly1305 for encryption. Output format: nonce(24) || ciphertext (ciphertext includes 16-byte auth tag).

      Parameters

      • message: Uint8Array

        The plaintext bytes to encrypt.

      • recipientPublicKey: Uint8Array

        The recipient's 32-byte Curve25519 public key.

      • senderSecretKey: Uint8Array

        The sender's 32-byte Curve25519 secret key.

      Returns Uint8Array

      A single Uint8Array with nonce prepended to ciphertext.

      If encryption fails.

      import { boxEncrypt, boxDecrypt } from "@polkadot-apps/crypto";
      import nacl from "tweetnacl";

      const alice = nacl.box.keyPair();
      const bob = nacl.box.keyPair();

      const packed = boxEncrypt(message, bob.publicKey, alice.secretKey);
      const plaintext = boxDecrypt(packed, alice.publicKey, bob.secretKey);