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).
nonce(24) || ciphertext
The plaintext bytes to encrypt.
The recipient's 32-byte Curve25519 public key.
The sender's 32-byte Curve25519 secret key.
A single Uint8Array with nonce prepended to ciphertext.
Uint8Array
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); Copy
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);
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).