SM4 encrypt/decrypt (GM/T 0002-2012)
Local SM4 per the Chinese national standard GM/T 0002-2012: 16-byte blocks and keys, 32-round unbalanced Feistel with a final reversal, ECB / CBC / CFB / OFB / CTR, PKCS#7 padding, hex or UTF-8 keys and IVs, text / hex / Base64 input and output.
Runs in your browserEvery computation happens in your browser — your data never leaves this device.
Result
Runs locally; keys and plaintext never leave the page.
Enter content to see the result
Input bytes: 0 · Output bytes: 0 · Block size: 0 · Mode used: 0
What this tool does
- Encrypt data with the national standard parameters for systems that support SM4.
- Verify a custom or hardware SM4 implementation against GM/T 0002-2012.
- Compare ECB / CBC / CTR outputs and padding.
Example
Input
Hello, world!
Output
10f1e19bf9643b027bda5e898e24a921
Verified against the GM/T 0002-2012 Appendix A.1 vector: key = plaintext = 0123456789abcdeffedcba9876543210 → 681edf34d206965e86b3e94f536e4246; ECB / CBC / CFB / OFB / CTR were cross-checked byte for byte against node:crypto sm4-*.
Frequently asked questions
How does SM4 relate to AES?
Both are 128-bit block ciphers but with completely different designs (SM4 is a 32-round unbalanced Feistel with a final reversal and its own key schedule), so the same key and plaintext give unrelated ciphertext. SM4 is the Chinese national standard used for domestic compliance.
Does it support SM2 or SM3?
No. This page does SM4 symmetric encryption only; SM2 signing/encryption and SM3 digests live on a separate national-crypto page.
Why must the IV be 16 bytes?
An SM4 block is 16 bytes, so CBC/CFB/OFB/CTR IVs must be 16 bytes or the tool reports invalid-iv.
What is wrong with ECB?
Identical plaintext blocks produce identical ciphertext blocks, leaking patterns; use it only for random data or comparison, and prefer CBC or CTR for real data.
Keywords:SM4GM/T 0002sm4 crypt