Polkadot Apps
    Preparing search index...

    Function sealedBoxEncrypt

    • Sealed box encrypt: uses an ephemeral keypair so the recipient cannot identify the sender.

      Output format: ephemeralPubKey(32) || nonce(24) || ciphertext. The ciphertext includes the 16-byte Poly1305 authentication tag.

      Parameters

      • message: Uint8Array

        The plaintext bytes to encrypt.

      • recipientPublicKey: Uint8Array

        The recipient's 32-byte Curve25519 public key.

      Returns Uint8Array

      A single Uint8Array containing the sealed message.

      If encryption fails (e.g. invalid public key).

      import { sealedBoxEncrypt, sealedBoxDecrypt } from "@polkadot-apps/crypto";
      import nacl from "tweetnacl";

      const recipient = nacl.box.keyPair();
      const sealed = sealedBoxEncrypt(message, recipient.publicKey);
      const plaintext = sealedBoxDecrypt(sealed, recipient.secretKey);