Encrypt a JSON-serialisable payload using secretbox (XChaCha20-Poly1305).
Hex-encoded 256-bit key.
Plaintext payload (will be JSON-stringified if not a string).
Base64-encoded sealed box.
const key = "a0b1c2..."; // 64-char hex string (256-bit)const sealed = encryptPayload(key, { userId: 42, role: "admin" });// sealed is a base64-encoded string ready for transport Copy
const key = "a0b1c2..."; // 64-char hex string (256-bit)const sealed = encryptPayload(key, { userId: 42, role: "admin" });// sealed is a base64-encoded string ready for transport
Encrypt a JSON-serialisable payload using secretbox (XChaCha20-Poly1305).