UFOZoo

SM4 Encryption — Chinese Symmetric Cipher Tool Online

Chinese national symmetric block cipher (GM/T 0002). Supports ECB and CBC modes for key generation, encryption, and decryption. Browser-based.

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
  • All operations performed locally in browser

How to Use

  1. 1Key Generation: Click 'Generate Key' to create a random 128-bit SM4 key.
  2. 2Encryption: Enter plaintext, key, select mode (ECB/CBC), and click 'Encrypt'.
  3. 3Decryption: Enter ciphertext, key, select mode, and click 'Decrypt'.
  4. 4CBC Mode: Requires an initialization vector (IV). Click 'Generate IV' to create one.
  5. 5ECB Mode: Each 128-bit block is encrypted independently — faster but can reveal patterns in your data.
  6. 6CBC Mode: Blocks are chained together with the IV — more secure, recommended for sensitive data.
  7. 7Store the key and IV separately. In CBC mode, never reuse the same IV with the same key.
  8. 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.

Related Tools