Symmetric Encryption Tutorial
Detailed guide, best practices, and FAQ
Use Cases
The symmetric encryption tool is useful for sensitive data transmission, config file encryption, API key protection, database field encryption, etc. Supports both international AES-256 and Chinese standard SM4: AES for global use, SM4 for compliance with Chinese cryptographic regulations. Both run locally in the browser; keys never leave the device.
Features
- AES-256-GCM: recommended mode with authentication tag, tamper-detecting
- AES-256-CBC + HMAC: legacy compatibility with an additional HMAC-SHA256 integrity check
- SM4-CBC + HMAC: Chinese standard cipher (GB/T 32907-2016), 128-bit key, IV and integrity check
- Password-derived: PBKDF2-SHA256 (600,000 iterations) + random salt for all modes
- Hex key: AES 64 hex / SM4 32 hex for advanced users
- Fully local: Web Crypto API + pure JS SM4, key never leaves the browser
- UTF-8 safe: correctly handles non-ASCII characters like Chinese
- v2 ciphertext format: v2: prefix with metadata bound to the ciphertext
Examples
Example 1: Scenario 1: Encrypt an API key for note storage — input the key, set a password, choose AES-GCM, click Encrypt, save the base64 ciphertext; decrypt later when needed.
Example 2: Scenario 2: Send a private message to a colleague — encrypt with a shared password, send the ciphertext via chat/email, the recipient decrypts with the same password.
Example 3: Scenario 3: Chinese compliance — financial/government systems requiring SM4; choose SM4-CBC mode, share the key via a secure channel.
Best Practices
- Prefer AES-GCM mode — authenticated, tamper-resistant
- For Chinese compliance, choose SM4-CBC (IV plus HMAC integrity check)
- Password at least 12 chars with mixed case, digits, symbols
- Higher PBKDF2 iterations = more secure (this tool uses 600,000)
- Always pair ciphertext with HTTPS to prevent MITM attacks
- Share hex keys only via secure channels (offline, password manager) — never in plaintext
FAQ
Will my password be uploaded?
No. All encryption/decryption is done locally in your browser; password and key never leave your device.
How to choose between AES and SM4?
Use AES-256-GCM for international use or when no compliance is required (more secure, authenticated). Use SM4 for Chinese compliance (finance/government/MLPS). Different key lengths: AES 256-bit, SM4 128-bit.
How to choose between GCM and CBC?
GCM is recommended — it has an authentication tag to detect tampering. CBC is mainly for legacy systems; this tool adds an HMAC-SHA256 integrity check on top, but new data should still prefer GCM.
What is the ciphertext format?
Always v2:base64(header + salt? + iv + ciphertext + HMAC?). The header records key source and algorithm; password mode includes a 16-byte salt; GCM binds metadata via AAD, while CBC/SM4-CBC append a 32-byte HMAC-SHA256.
Can legacy ciphertext still be decrypted?
No. Formats before v2 used a weaker key derivation and lacked integrity checks. This version only accepts ciphertext with the v2: prefix; re-encrypt with the same password.
What if decryption fails?
Check: 1) correct password/key 2) algorithm mode matches encryption 3) full ciphertext copied 4) correct key source (password/hex) selected.