Online SM4 Encryption Tool · CBC / ECB Mode

Compliant with GM/T 0002-2012 standard. Key and IV are both 16 characters, all calculations run locally for maximum security.

SM4 National Cryptography Algorithm Tool

GM/T 0002-2012

Supports CBC and ECB modes. Both key and IV must be 16 characters long (128 bits). All operations are executed locally to protect your data privacy.

This function needs to run in a browser environment and may not work under server-side rendering.

Quick Tips

  • The secret key must contain exactly 16 ASCII characters (128 bits). Chinese characters may cause length overflow issues.
  • A 16-character initialization vector is mandatory for CBC mode, and it is recommended to use a different value from the key.
  • Encryption outputs a hexadecimal string; input hexadecimal ciphertext when performing decryption operations.
  • All calculations are completed locally in your browser, so your keys and data will never be uploaded to any server.
  • If decryption fails, double-check that the key, IV and operating mode match the settings used during encryption.

Introduction to Online SM4 Encryption Tool

What is SM4 Algorithm?

SM4, formerly known as SMS4, is a block cipher algorithm officially released by China's State Cryptography Administration in 2012 for wireless local area network products, and it was later standardized as GM/T 0002-2012, the national cryptographic industry standard. Similar to the internationally recognized AES algorithm, SM4 features a 128-bit block size and a 128-bit key length, adopting a structure with 32 rounds of non-linear iteration. It has become a mainstream encryption solution widely deployed in government affairs systems, financial services, internet of things devices and other scenarios that require cryptographic compliance and data security protection. As a domestic commercial cipher algorithm, SM4 plays a core role in promoting independent and controllable information security construction across various industries.

This online SM4 encryption and decryption tool fully follows the specifications defined in GM/T 0002-2012. It implements the classic ECB and CBC operating modes together with PKCS#7 padding rules directly inside modern web browsers. It offers a convenient way for developers, security researchers and ordinary users to conduct algorithm verification, data encryption and decryption tests. Since all computational logic runs locally on the client side, there is no risk of sensitive data leakage during use, which ensures the confidentiality of your plaintext content and custom keys at all times.

Core Functions & Working Principles

The primary functions of this tool include plaintext encryption and ciphertext decryption based on the SM4 standard algorithm. It supports two most commonly used working modes in practical development: ECB and CBC. The underlying principle of SM4 relies on symmetric encryption technology, which means the identical secret key is applied for both encryption and decryption processes. The algorithm divides original data into fixed 128-bit blocks and processes each block through multiple rounds of complex transformations including substitution, permutation and XOR operations to generate unreadable ciphertext. When decryption is performed, the algorithm reverses all transformation steps using the same key to restore the original plaintext completely.

Different working modes bring distinct security characteristics. ECB mode processes every data block independently with the same key, which makes the operation simple and supports parallel computing, yet it cannot hide repeated data patterns effectively. CBC mode introduces an initialization vector to connect adjacent data blocks, so identical plaintext blocks will produce completely different ciphertext results, greatly enhancing overall security. This tool strictly restricts the length of both key and initialization vector to 16 characters, which corresponds to the standard 128-bit length required by the SM4 algorithm, avoiding abnormal operation caused by non-standard key configuration.

How to Use This SM4 Tool

Using this SM4 encryption and decryption tool is straightforward and does not require professional cryptographic knowledge. First, enter your custom secret key in the key input box, and make sure the key is exactly 16 ASCII characters long. Next, select your required operating mode from the drop-down menu between CBC and ECB. If you choose CBC mode, you need to fill in a 16-character initialization vector in the corresponding input field. After finishing configuration, paste the content you want to process into the data content area: input plaintext for encryption tasks, or paste hexadecimal ciphertext for decryption tasks.

Click the Encrypt button to convert plaintext into standard SM4 hexadecimal ciphertext, or click the Decrypt button to restore valid ciphertext back to readable plaintext. Once the operation completes, the result will be displayed in the result area below. You can click the copy button to quickly copy the output content to your clipboard for subsequent use. Remember not to use Chinese characters or special multi-byte symbols for keys and initialization vectors, as such content will change the actual bit length and lead to operation failures. Always keep your key confidential to guarantee the security of encrypted data.

Frequently Asked Questions

Q: What is the difference between SM4 and AES encryption algorithms?

A: Both SM4 and AES are symmetric block cipher algorithms with 128-bit block length and similar security strength. The main difference lies in origin and application scenarios. SM4 is China's domestic national cryptographic algorithm, which must be adopted in systems that need to meet national cryptographic compliance requirements, such as government platforms and financial business systems. AES is an international universal encryption standard. In terms of internal structure, SM4 uses 32 iteration rounds while AES has different round settings according to key lengths. This SM4 online tool is specially built for domestic cryptographic standard adaptation and daily testing work.

Q: Why does the key have to be exactly 16 characters?

A: The SM4 algorithm standard clearly defines that the key length is fixed at 128 bits. When using common ASCII characters, each character occupies 8 bits, so 16 characters just form a standard 128-bit key. If the key length is insufficient or exceeds 16 characters, the key bit length will not conform to the algorithm rules, resulting in encryption and decryption errors. Using multi-byte characters like Chinese will also change the actual bit count, so please stick to 16 single-byte ASCII characters for normal use.

Q: Which mode is more secure, CBC or ECB?

A: CBC mode is more secure in most application scenarios. ECB encrypts each data block separately, and repeated plaintext segments will generate identical ciphertext blocks, which is easy for attackers to analyze data features. CBC uses an initialization vector to perform XOR operation with the previous ciphertext block before encryption, effectively obscuring data patterns. It is recommended to choose CBC mode for formal business environments, while ECB can only be used for simple testing or compatibility with old legacy systems.

Q: Is my data safe when using this online SM4 tool?

A: Your data is fully secure. All encryption and decryption calculations run locally inside your browser, and none of your plaintext, keys or ciphertext will be uploaded to any remote server. We do not collect or store any user data. You can safely process sensitive text content. The only data transmission is basic page resource loading, which will not involve your business data and private keys.

Q: What should I do if decryption always fails?

A: Decryption failures are mostly caused by inconsistent configuration parameters. First check whether the key used for decryption is completely the same as the key used for encryption. If CBC mode is adopted, verify that the initialization vector is also consistent. Confirm that the selected encryption mode has not been switched by mistake. In addition, make sure the input ciphertext is a complete standard hexadecimal string without extra spaces or invisible symbols. Correcting the above items can solve most decryption failure problems.

Q: What common scenarios is the SM4 algorithm applied to?

A: SM4 is widely used in industries that require cryptographic compliance. It is commonly used for encryption transformation of old business systems to meet national cybersecurity assessment and cryptographic evaluation requirements. Developers also use SM4 to encrypt interface request parameters when docking with government and banking APIs. Besides, it is a classic learning case for students and cryptographic enthusiasts to learn block cipher principles and different encryption modes.