SM4 Encrypt / Decrypt

Free online SM4 (Chinese national cipher) encryption and decryption. ECB/CBC modes, Base64 or HEX output, full UTF-8 support. Runs in your browser.

Runs locally · data never uploaded
Advertisement

How to use

What it does

SM4 is a 128-bit block cipher published by China's State Cryptography Administration and widely used in finance and government systems. This tool supports ECB and CBC modes with hex or Base64 output, computed entirely in your browser.

Example

Set the key to 0123456789abcdeffedcba9876543210 (32 hex chars = 16 bytes), the plaintext to 你好,SM4!, choose CBC with IV fedcba98765432100123456789abcdef:

5c30dd7f8e5e03dfe9aa0ff955c989ea737e88cf97b7bffcc1237acd9458e08b

Switching "Output" to Base64 gives XDDdf45eA9/pqg/5VcmJ6nN+iM+Xt7/8wSN6zZRY4Is=.

Key & IV

The key is exactly 16 bytes: either ASCII (16 characters) or 32 hex chars. CBC also needs a 16-byte IV, and both sides must use the same IV.

FAQ

Q1.How is SM4 related to AES?
Both are 128-bit block ciphers with the same purpose but different inner structure. SM4 is the Chinese national standard, often used where compliance requires a domestic algorithm instead of AES.
Q2.Which is safer, ECB or CBC?
CBC is safer: it uses an IV so identical plaintexts encrypt to different ciphertexts and hides data patterns. ECB does not, so reserve it for random or tiny payloads.
Q3.Are my key and IV uploaded?
No. Encryption happens in JavaScript inside your browser; the tool works offline and the key stays on your device.
Q4.Why do I get garbage when decrypting?
Usually the key, IV or mode used for decryption differs from encryption. Make sure both ends use the exact same key, IV and mode, then try again.
Advertisement

Related tools