SM4 Encryption: Chinese Symmetric Cipher Tool Online
SM4 encryption online: Chinese national symmetric block cipher (GM/T 0002) with ECB and CBC modes for key generation, encryption, and decryption.
Updated 2026-08-16
Related Tools
SM2 Encryption: Chinese Asymmetric Crypto Tool Online
Adler-32 Checksum: zlib & PNG Fast Integrity Check
Bcrypt Password Hash Generator: Online Hash & Verify Tool
BLAKE2b-256 Hash: Faster Than MD5, Secure as SHA-3
BLAKE2b-512 Hash: 512-bit High-Speed BLAKE2 Hash Online
BLAKE2s-256 Hash: Embedded & IoT Optimized Hash Tool
Features
- Generate SM4 keys (128-bit)
- Encrypt data with SM4
- Decrypt ciphertext with SM4
- Support ECB and CBC modes
- Auto-generate initialization vector (IV)
- Chinese national standard GM/T 0002
- Fast symmetric encryption
- Suitable for large data encryption
- Hex key input/output
How to Use
- 1Key Generation: Click 'Generate Key' to create a random 128-bit SM4 key.
- 2Encryption: Enter plaintext, key, select mode (ECB/CBC), and click 'Encrypt'.
- 3Decryption: Enter ciphertext, key, select mode, and click 'Decrypt'.
- 4CBC Mode: Requires an initialization vector (IV). Click 'Generate IV' to create one.
- 5ECB Mode: Each 128-bit block is encrypted independently, faster but can reveal patterns in your data.
- 6CBC Mode: Blocks are chained together with the IV, more secure, recommended for sensitive data.
- 7Store the key and IV separately. In CBC mode, never reuse the same IV with the same key.
- 8Use hex format for key and IV input/output. Keys are 32 hex characters (128 bits).
Frequently Asked Questions
What is SM4?
SM4 is a symmetric block cipher algorithm published by the Chinese State Cryptography Administration (SCA) in 2006. It's part of the Chinese national cryptographic standard (GM/T 0002) and uses 128-bit keys and 128-bit blocks. SM4 is similar in design to AES and provides comparable security and performance.
What's the difference between ECB and CBC modes?
ECB (Electronic Codebook) encrypts each 128-bit block independently. It's fast but can reveal patterns in data. CBC (Cipher Block Chaining) XORs each plaintext block with the previous ciphertext block before encryption, providing better security. CBC requires an initialization vector (IV). Use CBC for most applications.
How does SM4 compare to AES?
SM4 and AES-128 both use 128-bit keys and blocks. SM4 uses 32 rounds while AES-128 uses 10 rounds. Performance is comparable, with SM4 being slightly slower on some platforms. Both provide 128-bit security. SM4 is mandatory in Chinese government and financial applications, while AES is the global standard.
Is SM4 secure?
SM4 has been extensively analyzed by cryptographers since 2006. No practical attacks have been found. It was included in ISO/IEC 18033-3 in 2011, confirming its international recognition. SM4 is considered cryptographically strong and is widely used in Chinese critical infrastructure.
How should I store the key and IV?
The key must be kept secret and stored securely. Use environment variables, secret management systems, or hardware security modules (HSM). The IV doesn't need to be secret but should be unique for each encryption. Never reuse the same key+IV combination in CBC mode.
What is the block size of SM4?
SM4 uses a 128-bit (16-byte) block size, same as AES. Data is divided into 128-bit blocks for encryption. If the plaintext length isn't a multiple of 16 bytes, SM4 automatically applies PKCS#7 padding to fill the remaining space. This padding is removed automatically during decryption.
How many rounds does SM4 use?
SM4 uses 32 rounds of encryption, compared to AES-128 which uses 10 rounds. Each round applies a combination of substitution (S-box), permutation (linear transformation), and key mixing operations. The 32-round design provides a strong security margin against cryptanalytic attacks.
Can SM4 be used for file encryption?
Yes, SM4 is well-suited for file encryption due to its high speed. For files larger than the block size (16 bytes), the cipher mode (ECB or CBC) determines how blocks are processed. CBC mode is recommended for files to prevent pattern leakage. The hex output can be decoded and stored as a binary encrypted file.
What is the difference between SM4 and DES/3DES?
SM4 uses 128-bit keys and 128-bit blocks with 32 rounds, providing modern security. DES uses 56-bit keys (too weak for modern use) and 64-bit blocks. 3DES improves on DES with up to 112-bit security but is significantly slower and still uses 64-bit blocks. SM4 is both more secure and more efficient than DES/3DES.
Is SM4 compliant with international standards?
Yes, SM4 was included in ISO/IEC 18033-3 in 2021 as an international standard block cipher. It is recognized by ISO alongside AES, Camellia, and other major ciphers. This means SM4 can be used in international systems that require standardized cryptographic algorithms.
Why does SM4 decryption fail?
SM4 is a block cipher with a fixed 128-bit block, so the usual culprits are: a wrong key (any single byte difference breaks the whole block), a mismatched mode or IV (CBC and ECB produce different ciphertexts for the same key), missing or wrong padding (PKCS#7 is standard), and ciphertext that was modified or truncated in transit. Verify key, mode, IV, and padding are identical on both sides before anything else.
Why doesn't the ciphertext from my backend (Java or Python) match this tool's output?
SM4 output depends on four things that must match on both sides: the cipher mode (ECB vs CBC), the IV in CBC mode, the padding scheme (PKCS#7 is the standard), and the encoding (hex vs Base64 for key, IV, and ciphertext). A single difference (for example, a library that defaults to PKCS#5 padding or encodes output as Base64 while this tool shows hex) makes the ciphertext completely different. Check all four on both sides before debugging anything else.
Why does encrypting the same text with the same key produce different ciphertext every time?
In CBC mode the tool generates a fresh random IV for every run, so the same key and plaintext produce different ciphertext each time: that is a security feature, not a bug. A unique IV prevents identical plaintext blocks from leaking patterns. In ECB mode the same input always yields the same output. To reproduce a previous result, reuse the exact same key, IV, mode, and padding.
Can SM4 encryption be reversed without the key?
No. SM4 encryption is a 128-bit block cipher, and reversing ciphertext without the key means brute-forcing up to 2^128 keys: infeasible with current hardware. The SM4 encryption algorithm is designed so that only the holder of the key can decrypt. One honest warning: SM4 encryption is reversible when the key is known, so do not use it to store passwords or secrets where an attacker might obtain the key. Use a password hash like bcrypt or Argon2 instead.
Why is SM4 encryption online slow on very large data?
SM4 encryption runs in JavaScript inside your browser here, and JS is typically 2-5x slower than native C libraries, so multi-megabyte inputs can take a while: the benefit is that nothing ever leaves your device. For large files, prefer a native tool (OpenSSL with the SM4 provider, GmSSL, or a national-standard library); if you must use this SM4 encryption online tool, encrypt in chunks or reduce the input size.