Crypto Middleware
    Preparing search index...

    Function encryptPayload

    • Encrypt a JSON-serialisable payload using secretbox (XChaCha20-Poly1305).

      Parameters

      • key: string

        Hex-encoded 256-bit key.

      • data: unknown

        Plaintext payload (will be JSON-stringified if not a string).

      Returns 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