SM4 National Encryption Tool Icon

SM4 National Encryption

Online SM4 National Symmetric Encryption and Decryption Tool, supporting five working modes: ECB/CBC/CFB/OFB/CTR, and multiple padding methods. All operations are performed locally in the browser to ensure data security.

Tool Description

SM4 National Encryption is an online SM4 Chinese national standard symmetric encryption/decryption tool. SM4 is a block cipher algorithm published by Chinas State Cryptography Administration (GB/T 32907-2016), with both block size and key length fixed at 128 bits (16 bytes). This tool supports ECB / CBC / CFB / OFB / CTR five cipher modes, PKCS#7 / ISO 9797-1 / ANSI X.923 / ISO 10126 / Zero Padding / No Padding six padding schemes, and Base64 / Hex two output encodings. All operations are performed locally in your browser — no data is ever uploaded to any server.

How to Use

  1. Set the Key

    Enter or click the random button to generate a key (SM4 uses a fixed 16-byte, 128-bit key)

  2. Choose the Mode

    Select a cipher mode (ECB / CBC / CFB / OFB / CTR). Non-ECB modes require an IV offset (16 bytes)

  3. Configure Parameters

    Choose a padding scheme and output encoding (Base64 / Hex), then paste or type text into the input area

  4. Run the Operation

    Click "Encrypt" to encrypt or "Decrypt" to decrypt

  5. Save the Result

    The result will appear on the right — you can copy or download it, or use the swap button to exchange input and output

Use Cases

  • National Cipher Compliance: Meet China's classified information system security protection and cryptographic application security assessment requirements, replacing foreign encryption algorithms
  • Government & Financial Systems: SM4 is widely used in China's e-government, banking, securities, power grids, and other critical information infrastructure for data encryption protection
  • Secure Communication: Encrypt data with SM4 during front-end/back-end communication and IoT device communication to ensure data transmission confidentiality

Key Advantages

  1. National Standard Algorithm

    Strictly follows the Chinese national standard GB/T 32907-2016 "SM4 Block Cipher Algorithm", meeting national crypto compliance requirements

  2. Free Daily Usage

    Free daily usage is provided for every user, so routine encryption needs can be met at zero cost; frequent or professional use can unlock more quota by subscribing to membership

  3. Privacy & Security

    All encryption and decryption run entirely in your browser; your key and data are never uploaded to any server, providing 100% privacy protection

  4. Five Cipher Modes

    Supports ECB / CBC / CFB / OFB / CTR — five mainstream cipher modes covering most business scenarios

  5. Multiple Padding & Encoding

    Provides PKCS#7, ISO 9797-1, ANSI X.923, ISO 10126, Zero, No padding schemes plus Base64 / Hex output encodings

  6. Random Key Generation

    Built-in secure random key and IV generation lets you create length-compliant, high-strength keys in one click, simplifying setup

Cipher Mode Description

Different cipher modes determine how data blocks relate to each other, affecting security and applicable scenarios:

Mode Full Name Requires IV Description
ECBElectronic CodebookNoEach block is encrypted independently; identical plaintext produces identical ciphertext — not recommended for long texts
CBCCipher Block ChainingYesEach block depends on the previous ciphertext block; high security, the most commonly used mode
CFBCipher FeedbackYesConverts block cipher to stream cipher; suitable for real-time encryption
OFBOutput FeedbackYesConverts block cipher to stream cipher; errors do not propagate
CTRCounter ModeYesConverts block cipher to stream cipher; supports parallel processing, good performance

Padding Scheme Description

When the plaintext length is not a multiple of the block size (16 bytes), padding is needed:

  • PKCS#5 / PKCS#7 - Most commonly used; pads with the number of missing bytes (e.g., missing 5 bytes → pad with 0x05 0x05 0x05 0x05 0x05)
  • ISO 9797-1 - First byte is 0x80, remaining bytes are 0x00
  • ANSI X.923 - Last byte records padding length, remaining bytes are 0x00
  • ISO 10126 - Last byte records padding length, remaining bytes are random
  • Zero Padding - Pads with 0x00 to block size; no padding is added if plaintext is already a multiple of block size
  • No Padding - No padding; plaintext length must be a multiple of block size (16 bytes)

SM4 Algorithm Introduction

SM4 (formerly SMS4) is a symmetric block cipher published by China's State Cryptography Administration, one of the core algorithms in China's national cryptographic standard system:

  • Block Size - 128 bits (16 bytes)
  • Key Length - 128 bits (16 bytes)
  • Encryption Rounds - 32 rounds of nonlinear iterative structure
  • Design Structure - Unbalanced Feistel network, combining S-box nonlinear transformation and linear diffusion layer
  • National Standard - GB/T 32907-2016 "Information Security Technology — SM4 Block Cipher Algorithm"

SM4 vs Other Encryption Algorithms

Compare SM4 with AES, DES, and other symmetric encryption algorithms:

Dimension SM4 AES DES
Block Size128 bits128 bits64 bits
Key Length128 bits128/192/256 bits56 bits
Encryption Rounds32 rounds10/12/14 rounds16 rounds
SecurityHigh, national standardHigh, international standardLow, can be brute-forced
StandardizationChinese national standard GB/T 32907International standard NIST FIPS 197Legacy standard, deprecated

FAQ

What is SM4? What's the difference between SM4 and SMS4?

SM4 (formerly SMS4) is a symmetric block cipher algorithm published by China's State Cryptography Administration in 2006, confirmed as a national cryptographic industry standard in 2012, and became a national standard (GB/T 32907-2016) in 2016. SMS4 is the old name, SM4 is the official name after standardization — the two algorithms are identical, only the name was simplified from "SMS4" to "SM4".

What's the difference between SM4 and AES? Which should I use?

Both are secure symmetric block ciphers: SM4 has a 128-bit block size, fixed 128-bit key, 32 rounds, and is a Chinese national standard; AES has a 128-bit block size, supports 128/192/256-bit keys, 10/12/14 rounds, and is an international standard. For information systems within China, especially in government, finance, and other critical sectors, SM4 should be prioritized to meet national cipher compliance requirements. For international scenarios, AES offers broader compatibility.

What are the key requirements for SM4?

SM4 key length is fixed at 128 bits (16 bytes). English letters, digits, and symbols each occupy 1 byte; a Chinese character typically occupies 3 bytes. We recommend using a 16-character alphanumeric combination as the key, or clicking the random generation button next to the key input field to automatically generate a compliant key.

Must encryption and decryption parameters be exactly the same?

Yes, decryption must use exactly the same key, cipher mode, padding scheme, and output encoding as encryption — otherwise decryption will fail or produce garbled output. The IV offset must also be identical (except in ECB mode). It's recommended to save the encryption parameters together with the ciphertext.

Which cipher mode is most secure?

CBC mode is generally recommended — it is the most commonly used mode with good security and broad compatibility. ECB mode is not recommended for sensitive data as identical plaintext produces identical ciphertext, risking pattern leakage. CFB, OFB, and CTR convert the block cipher to a stream cipher, suitable for real-time encryption scenarios.

Why is the decryption result empty?

Possible reasons: ① Incorrect key or mismatched length (must be 16 bytes); ② Cipher mode or padding scheme does not match what was used for encryption; ③ Wrong output encoding (if Base64 was used for encryption, select Base64 for decryption too); ④ The input is not valid SM4 encrypted data.

Is my data uploaded to a server?

No. All encryption/decryption operations run entirely in your browser. Your keys and data never leave your device.

Which cipher modes and padding schemes are supported?

The tool supports ECB / CBC / CFB / OFB / CTR cipher modes and PKCS#7 / ISO 9797-1 / ANSI X.923 / ISO 10126 / Zero Padding / No Padding padding schemes, covering most integration scenarios. ECB mode needs no IV, while other modes require a 16-byte IV offset.

Is this tool free? Do I need to register?

This tool provides free daily usage, so routine lightweight needs can be met at zero cost. No registration or login is required — just open the page and use it. When you need higher processing volumes or more frequent use, subscribing to membership unlocks more benefits to handle various scenarios with ease.

Does it support Chinese and other non-ASCII characters?

Absolutely. The tool processes text using UTF-8 encoding, so Chinese, Japanese, Korean, and any other Unicode characters can be encrypted and decrypted normally. Text is converted to UTF-8 byte sequences when encrypting and restored when decrypting.

Which is faster, SM4 or AES?

Their performance is very close; both are efficient symmetric block ciphers. SM4 uses 32 rounds, while AES uses 10/12/14 rounds (depending on key length). For ordinary text, both SM4 and AES complete encryption/decryption instantly in the browser — users can barely notice a difference.

What if decryption fails in No Padding mode?

No Padding mode requires the plaintext length to be a multiple of 16 bytes. If decryption errors or produces garbled output, check: ① whether the plaintext length used during encryption was a multiple of the block size; ② whether the ciphertext length is a multiple of 16 bytes; ③ whether the key, mode, and IV exactly match those used during encryption.

Content last updated:2026-07-15

Related Tools

DES Encryption

DES Encryption

Online DES/2DES/3DES encryption and decryption tool, supporting all encryption modes and padding methods. Fully processed locally in the browser for security and efficiency.

AES Encryption

AES Encryption

Online AES encryption and decryption tool, supporting AES-128/192/256, covering all encryption modes and padding methods, secure, efficient, and easy to operate.

3DES Encryption

3DES Encryption

Online 3DES encryption/decryption tool, supporting all encryption modes and padding methods, fully processed locally in the browser to ensure data security.

RC4 Encryption

RC4 Encryption

Online RC4 stream cipher encryption/decryption tool, supports multiple key lengths, one-click encryption and decryption, all operations are completed locally in the browser to ensure data security.

Rabbit Encryption

Rabbit Encryption

Online Rabbit stream cipher encryption/decryption tool, using a high-speed symmetric encryption algorithm, supporting multiple key lengths. All operations are performed locally in the browser to ensure data security.

RC2 Encryption

RC2 Encryption

Online RC2 encryption and decryption tool, supporting ECB/CBC modes, variable key length and effective key bits, all processed locally in the browser to ensure data security.

IDEA Encryption

IDEA Encryption

Online IDEA International Data Encryption Algorithm Tool, supporting multiple encryption modes including ECB/CBC/CFB/OFB/CTR. All operations are performed locally in the browser to ensure data security.

Blowfish Encryption

Blowfish Encryption

Online Blowfish encryption/decryption tool supporting 128/192/256/448-bit variable keys, ECB/CBC/CFB/OFB modes, and multiple padding methods. All operations are performed locally in the browser to ensure data security.

CAST Encryption

CAST Encryption

CAST-128 (CAST5) online encryption and decryption tool, supporting multiple encryption modes such as ECB/CBC/CFB/OFB, flexible padding methods, and output encoding. All operations are performed locally in the browser, ensuring security and efficiency.

RSA Encryption and Decryption

RSA Encryption and Decryption

Online RSA asymmetric encryption and decryption tool, supporting key pair generation, public key encryption and private key decryption, private key signing and public key verification. All operations are performed locally in the browser to ensure data security.

MD5 Encryption

MD5 Encryption

Online MD5 hash encryption tool, supporting 16-bit/32-bit output, case switching, and file MD5 verification. All operations are completed locally in the browser, ensuring security and efficiency.

MD2 Encryption

MD2 Encryption

MD2 Encryption Tool: Generate 32-bit MD2 hash values online, supporting uppercase/lowercase output and file verification.

SHA-1 Encryption

SHA-1 Encryption

Online SHA-1 hash calculation tool for efficient text encryption and file integrity verification.

SHA-256 Encryption

SHA-256 Encryption

Online SHA-256 hash calculation tool for quick text encryption and file integrity verification.

SHA-384 Encryption

SHA-384 Encryption

Online SHA-384 hash calculation tool for fast text encryption and file integrity verification.

SHA-512 Encryption

SHA-512 Encryption

Online SHA-512 hash calculation tool, supporting text encryption and file integrity verification, quickly generating secure hash values.

SM3 National Encryption

SM3 National Encryption

Online SM3 National Hash Encryption Tool, supports text hash calculation and file verification, outputs a 256-bit hash value, compliant with GM/T 0004-2012 national standard.

Base64 Encode/Decode

Base64 Encode/Decode

Online Base64 encode/decode tool, supporting text Base64 encoding and decoding, all done locally in the browser, safe and efficient.

URL Encode/Decode

URL Encode/Decode

Online URL encoding and decoding tool, supports intelligent encoding and decoding of URL parameters, automatically identifies URL structure, processes only the parameter part, completes entirely in the browser locally, safe and efficient.

UTF-8 Encode/Decode

UTF-8 Encode/Decode

Online UTF-8 encoding/decoding tool, supporting conversion between text and UTF-8 hexadecimal bytes. All processing is done locally in the browser, ensuring data security.

General Membership

Enjoy membership benefits

Exclusive Benefits

  • Unlimited use of 290+ web tools
  • Cross-platform benefits
  • New tools included
  • Free updates

Basic Benefits

  • Larger file size
  • More files
  • Full features on web
  • Full features on desktop

Monthly Member Plan

¥ 8.9
Original: ¥19.9
Valid for 30 days

Quarterly Member Plan

¥ 19.9
Original: ¥59.9
As low as 6.6 yuan/month
Hot

Yearly Member Plan

¥ 69.9
Original: ¥229.9
As low as 5.8 yuan/month
Pay: ¥ 9

Please scan with WeChat to pay

Payment indicates your agreement to the relevant terms

*No 7-day unconditional refund