ChaCha20-Poly1305 & Salsa20 Encrypt Online | Stream Cipher Browser
Encryption How It Works
What Is ChaCha20 / Salsa20?
ChaCha20 is a modern stream cipher designed by Daniel J. Bernstein as an improved variant of Salsa20. It provides high-speed encryption with excellent diffusion properties. ChaCha20-Poly1305 is an AEAD (Authenticated Encryption with Associated Data) construction that combines ChaCha20 for confidentiality with Poly1305 for authentication — detecting any tampering with the ciphertext.
This tool provides ChaCha20 and Salsa20 stream cipher encryption using the audited @noble/ciphers library. Choose between Passphrase mode (PBKDF2 key derivation with auto-generated salt and nonce) or Raw Key mode (direct key/nonce input in hex, Base64, or text). All cryptographic operations happen locally in your browser — your data never leaves your device.
When to Use ChaCha20
- Modern encryption protocols — TLS 1.3, WireGuard VPN, and SSH all support ChaCha20-Poly1305
- Mobile and IoT devices — ChaCha20 is software-optimized and faster than AES on devices without AES hardware acceleration
- Authenticated encryption — Use ChaCha20-Poly1305 when you need both confidentiality and integrity
- Random nonce scenarios — XChaCha20's 192-bit nonce makes random generation safe without counter management
- Legacy system compatibility — Salsa20 for backward compatibility with older systems
- When NOT to use — For block cipher requirements, use AES instead; ChaCha20 is a stream cipher
Algorithm Variants
| Variant | Nonce | Authenticated | Best for |
|---|---|---|---|
| ChaCha20 | 96-bit (12 bytes) | No | Raw stream cipher, custom protocols |
| ChaCha20-Poly1305 | 96-bit (12 bytes) | Yes (Poly1305 tag) | General-purpose, TLS 1.3, WireGuard |
| XChaCha20 | 192-bit (24 bytes) | No | Random nonce scenarios, no counter management |
| XChaCha20-Poly1305 | 192-bit (24 bytes) | Yes (Poly1305 tag) | Authenticated encryption with random nonces |
| Salsa20 | 64-bit (8 bytes) | No | Legacy compatibility (predecessor to ChaCha20) |
Standards Compliance
- RFC 8439 — ChaCha20 and Poly1305 for IETF Protocols (2018)
- TLS 1.3 — RFC 8446 (2018), mandates ChaCha20-Poly1305 as a cipher suite
- WireGuard — Uses ChaCha20-Poly1305 for VPN encryption
- NIST — ChaCha20 is not NIST-standardized but widely adopted as AES alternative
Last updated:
Code Examples
Encrypt with ChaCha20-Poly1305 using well-audited libraries:
JavaScript — @noble/ciphers (Browser)
import { chacha20poly1305 } from '@noble/ciphers/chacha';
import { randomBytes } from '@noble/ciphers/utils';
const key = randomBytes(32); // 256-bit key
const nonce = randomBytes(12); // 96-bit nonce
const aad = new TextEncoder().encode('additional data');
const cipher = chacha20poly1305(key, nonce, aad);
const plaintext = new TextEncoder().encode('secret message');
const ciphertext = cipher.encrypt(plaintext);
console.log('Ciphertext:', Buffer.from(ciphertext).toString('base64')); Python — PyCryptodome
from Crypto.Cipher import ChaCha20_Poly1305
import os
key = os.urandom(32)
nonce = os.urandom(12)
cipher = ChaCha20_Poly1305.new(key=key, nonce=nonce)
plaintext = b'secret message'
ciphertext, tag = cipher.encrypt_and_digest(plaintext)
print(f'Ciphertext: {ciphertext.hex()}')
print(f'Tag: {tag.hex()}') Go — crypto/chacha20poly1305
package main
import (
"crypto/rand"
"fmt"
"golang.org/x/crypto/chacha20poly1305"
)
func main() {
key := make([]byte, chacha20poly1305.KeySize)
rand.Read(key)
aead, _ := chacha20poly1305.New(key)
nonce := make([]byte, aead.NonceSize())
rand.Read(nonce)
plaintext := []byte("secret message")
ciphertext := aead.Seal(nil, nonce, plaintext, nil)
fmt.Printf("Ciphertext: %x\n", ciphertext)
} Rust — chacha20poly1305 crate
use chacha20poly1305::{
aead::{Aead, KeyInit, OsRng},
ChaCha20Poly1305, Nonce,
};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let key = ChaCha20Poly1305::generate_key(&mut OsRng)?;
let cipher = ChaCha20Poly1305::new(&key);
let nonce = ChaCha20Poly1305::generate_nonce(&mut OsRng);
let plaintext = b"secret message";
let ciphertext = cipher.encrypt(&nonce, plaintext.as_ref())?;
println!("Ciphertext: {:?}", ciphertext);
Ok(())
} Node.js — crypto module
const crypto = require('crypto');
const key = crypto.randomBytes(32);
const nonce = crypto.randomBytes(12);
const cipher = crypto.createCipheriv('chacha20-poly1305', key, nonce, {
authTagLength: 16
});
const plaintext = 'secret message';
const ciphertext = Buffer.concat([
cipher.update(plaintext, 'utf8'),
cipher.final()
]);
const authTag = cipher.getAuthTag();
console.log('Ciphertext:', ciphertext.toString('base64'));
console.log('Auth tag:', authTag.toString('base64')); Common Pitfalls & Attack Vectors
Security Notes
Disclaimer
Disclaimer: This page is for educational and testing purposes only. It does not constitute professional security advice. For production encryption systems, consult official standards (RFC 8439, NIST) and conduct a formal security review.
Further Reading & Standards
- RFC 8439 — ChaCha20 and Poly1305 for IETF Protocols
- TLS 1.3 — RFC 8446: The Transport Layer Security Protocol Version 1.3
- WireGuard — WireGuard Protocol Specification
- Daniel J. Bernstein's ChaCha Specification — Original ChaCha Design
Related Concepts
- Symmetric vs Asymmetric Encryption — Understanding the difference between shared-key and public-key cryptography
- AES Encryption — The NIST-standard block cipher alternative to ChaCha20
- Key Management — Best practices for generating and protecting encryption keys
- Passphrase Generation — Creating strong passphrases for encryption keys
Related Tools
Need block cipher encryption instead? Try AES Encrypt/Decrypt for NIST-standard security. For generating strong passphrases to use as encryption keys, the Passphrase Generator creates memorable, high-entropy phrases. To learn about XOR-based educational ciphers, try the XOR Encrypt/Decrypt tool.
Frequently Asked Questions
Which variant should I choose: ChaCha20, XChaCha20, or ChaCha20-Poly1305?
Use ChaCha20-Poly1305 for most cases — it provides authenticated encryption (AEAD) that detects tampering. Use plain ChaCha20 only when you need raw stream cipher output without authentication. Use XChaCha20 or XChaCha20-Poly1305 when you need a larger 192-bit nonce for random nonce generation safety.
What is the difference between ChaCha20 and ChaCha20-Poly1305?
ChaCha20 is a stream cipher that provides confidentiality only. ChaCha20-Poly1305 is an AEAD construction that combines ChaCha20 for encryption with Poly1305 for authentication. AEAD ensures both confidentiality and integrity — it detects any tampering with the ciphertext. Always prefer ChaCha20-Poly1305 unless you have a specific reason to use plain ChaCha20.
What is Passphrase mode?
Passphrase mode derives a 256-bit encryption key from your passphrase using PBKDF2 (100,000 iterations, SHA-256). The salt and nonce are auto-generated for each encryption, so you only need to remember your passphrase. The output is Base64-encoded and includes the salt and nonce for decryption. This is ideal when you want to encrypt without managing raw keys and nonces manually.
What happens if I reuse a nonce with the same key?
Reusing a nonce with the same key completely breaks ChaCha20 security — an attacker can XOR two ciphertexts to recover both plaintexts. Always use a unique nonce per key. In Passphrase mode, nonces are randomly generated and embedded in the output, so this is handled automatically.
What nonce length do I need?
ChaCha20 and ChaCha20-Poly1305 require a 96-bit (12-byte) nonce. XChaCha20 and XChaCha20-Poly1305 require a 192-bit (24-byte) nonce. Salsa20 requires a 64-bit (8-byte) nonce. The tool validates nonce length automatically in Raw Key mode.
Privacy: This tool runs entirely in your browser — nothing is uploaded or stored. · Disclaimer: For educational purposes only. Not professional security advice.
More in Encryption
AES Encrypt/Decrypt
Encrypt and decrypt with AES-128/192/256 online. GCM, CTR, and OpenSSL-compatible CBC modes. Passphrase or raw key, custom IV.
RSA Encrypt / Decrypt
Encrypt and decrypt with RSA-OAEP online via Web Crypto API. Built-in key generator, PKCS#8/PKCS#1 conversion, SHA-256/384/512.
DES Encrypt/Decrypt
Encrypt and decrypt with DES or 3DES (Triple DES) online. CBC/ECB/CFB/OFB modes, PKCS7/NoPadding, OpenSSL compatible.
XOR Encrypt/Decrypt
Encrypt and decrypt with XOR cipher online. Text/Hex/Base64 formats, visual XOR table, brute-force key breaking, auto-solve.
JWE Encrypt / Decrypt
Encrypt and decrypt JWE (JSON Web Encryption) tokens online. RSA-OAEP, AES key wrap, PBES2 password-based key management, A128GCM/A256GCM.
Blowfish Encrypt/Decrypt
Encrypt and decrypt with Blowfish online. 5 cipher modes, 5 paddings, GBK/UTF-16 support, OpenSSL passphrase compatible.
PGP Encrypt / Decrypt
Encrypt, decrypt, sign, and verify with OpenPGP online. Public key and password modes, built-in key generator, GnuPG compatible.