# NaCl Secretbox encrypt/decrypt

Encrypt or decrypt NaCl secretbox data with a 32-byte shared key and 24-byte nonce. Free, local, and browser-based.

## Run it

- **CLI:** `gizza tool nacl-secretbox-encrypt 'operation=encrypt'`
- **Web:** https://gizza.ai/tools/nacl-secretbox-encrypt/
- **Agents:** machine-readable descriptor (parameters JSON Schema) at https://gizza.ai/tools/nacl-secretbox-encrypt/tool.json

## Inputs

- `operation` — Operation _(field)_
- `data` — Data _(field)_
- `key` — Shared key _(field)_
- `nonce` — Nonce _(field)_
- `key_encoding` — Key encoding _(field)_
- `nonce_encoding` — Nonce encoding _(field)_
- `data_encoding` — Data encoding _(field)_
- `output_encoding` — Output encoding _(field)_

## Output

- Result (text)

## Query parameters

Open the tool pre-filled and auto-run via URL:

- `operation` — Operation
- `data` — Data
- `key` — Shared key
- `nonce` — Nonce
- `key_encoding` — Key encoding
- `nonce_encoding` — Nonce encoding
- `data_encoding` — Data encoding
- `output_encoding` — Output encoding

Example: `https://gizza.ai/tools/nacl-secretbox-encrypt/?operation=encrypt&data=Plaintext%20for%20encrypt%2C%20or%20nonce%2Bciphertext%2Btag%20for%20decrypt&key=00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff&nonce=000102030405060708090a0b0c0d0e0f1011121314151617&key_encoding=hex&nonce_encoding=hex&data_encoding=text&output_encoding=base64`

---

## About this tool

NaCl Secretbox is the classic libsodium `crypto_secretbox` construction: XSalsa20 for encryption plus Poly1305 for authentication. It is designed for shared-key messages where both sides already have the same 32-byte key and can choose a unique 24-byte nonce for every message.

This tool seals plaintext into a combined `nonce || ciphertext || tag` blob, or opens a combined blob and verifies the Poly1305 tag before returning the plaintext. It is useful when you need to inspect or interoperate with Secretbox-style payloads from libsodium-compatible systems without sending data to a server.

### Worked examples

- Use **Encrypt text → base64 box** to seal `attack at dawn` with the sample 32-byte key and 24-byte nonce. The output is a base64-encoded combined box containing the nonce prefix, ciphertext, and 16-byte authentication tag.
- Use **Encrypt text → hex box** when another system expects lowercase hexadecimal bytes.
- Use **Decrypt combined base64 box** to open the sample combined box and recover the exact plaintext `attack at dawn`.

### Limits and edge cases

- The key must decode to exactly 32 bytes. A password or passphrase is not stretched into a key; derive a key first with a KDF tool if needed.
- The nonce must decode to exactly 24 bytes and must be unique for every message encrypted with the same key. Reusing a nonce with Secretbox can reveal plaintext relationships.
- Encryption requires an explicit nonce so results are reproducible across CLI/page tests. Decryption can read the nonce from the combined box, or accept a separate nonce when `data` contains only `ciphertext || tag`.
- This is NaCl Secretbox / XSalsa20-Poly1305, not IETF ChaCha20-Poly1305 and not public-key sealed boxes.

## FAQ

<details>
<summary>What should I put in the nonce field?</summary>

Use 24 random bytes encoded as hex or base64, and never reuse the same nonce with the same key. The nonce is not secret, so encryption output prepends it to the ciphertext automatically.

</details>

<details>
<summary>Can I use a password as the key?</summary>

Only if the password text is exactly 32 UTF-8 bytes and you intentionally select `key_encoding=text`. In most real workflows you should first derive a 32-byte key from a password with a dedicated KDF such as Argon2, scrypt, or PBKDF2.

</details>

<details>
<summary>Why does decryption fail after I edit one byte?</summary>

Secretbox is authenticated encryption. The Poly1305 tag covers the ciphertext, so any wrong key, wrong nonce, truncated data, or tampered byte causes tag verification to fail before plaintext is returned.

</details>

<details>
<summary>Is this compatible with libsodium crypto_secretbox?</summary>

Yes for the primitive and byte sizes: 32-byte key, 24-byte nonce, XSalsa20 stream encryption, and a 16-byte Poly1305 tag. This tool's encryption output format is a convenient combined blob: `nonce || ciphertext || tag`.

</details>

## Related tools

- [Fernet token tool](https://gizza.ai/tools/fernet-token/): Create and read Fernet tokens (AES-128-CBC + HMAC-SHA256) in your browser: generate a key, encrypt to a url-safe token, decrypt with optional TTL. No upload.
- [AES cipher](https://gizza.ai/tools/aes-cipher/): Encrypt or decrypt text with AES in CBC, CTR, GCM or ECB mode and 128/192/256-bit keys, with hex/base64 I/O — in your browser. Nothing is uploaded.
- [AES Key Wrap](https://gizza.ai/tools/aes-key-wrap/): Wrap and unwrap cryptographic keys with AES Key Wrap (KW / RFC 3394, KWP / RFC 5649) using a 128/192/256-bit KEK — hex or base64, free and in-browser.
- [Argon2 hash](https://gizza.ai/tools/argon2-hash/): Hash a password with Argon2id (configurable memory, iterations, parallelism) and get a PHC string, or verify a password — in your browser. Nothing is uploaded.
- [ASN.1 / DER parser](https://gizza.ai/tools/asn1-parser/): Parse an ASN.1 / DER hex string into a readable tree of tags, lengths, OIDs and values — free, in your browser. Inspect X.509 certificates, keys and CSRs.
