SM4 (国密) Encrypt & Decrypt

Free online SM4 (国密) Encrypt & Decrypt tool. 100% local processing — your data never leaves your device.

National Standards
Legacy
Output

Result will be displayed here...

Input Encrypt

Usage Guide

About SM4

SM4 is a symmetric encryption algorithm released by China's State Cryptography Administration in 2012, and is an important component of the Chinese Commercial Cryptography Standard (GM/T 0002-2012). SM4 uses a 128-bit key and 128-bit block length, with security comparable to AES-128, specifically designed for Chinese cryptographic application scenarios. SM4 is widely used in China's financial, government, and telecommunications sectors, and is one of the core components of the national cryptography algorithm system. According to the Cryptography Law of the People's Republic of China, important fields involving national security and people's livelihood should use national cryptography algorithms.

National Cryptography Standard: SM4 is the symmetric encryption algorithm of China's Commercial Cryptography Standard, forming a complete national cryptography algorithm system together with SM3 (hash), SM2 (asymmetric encryption), and SM9 (identity-based cryptography). In critical sectors such as finance, government, and telecommunications within China, the use of national cryptography algorithms is recommended or mandatory.

Usage Steps

SM4 is a symmetric encryption algorithm that uses the same key for both encryption and decryption:

1. Select ModeChoose encryption mode (CBC, ECB), CBC mode recommended
2. Set KeyEnter or generate a 128-bit key (16 bytes), the key must be kept secret
3. Set IVCBC mode requires an Initialization Vector (IV), use a different random IV for each encryption
4. Encrypt DataEnter plaintext, click 'Encrypt' button to get ciphertext
5. Decrypt DataUse the same key, IV, and mode, enter ciphertext, click 'Decrypt' button to recover plaintext
Privacy Protection: All calculations are performed locally in your browser, data is never uploaded to servers, completely offline processing.

Algorithm Features

SM4 is based on the Feistel structure with the following technical characteristics:

National StandardChinese Commercial Cryptography Standard (GM/T 0002-2012), compliant with Cryptography Law requirements
128-bit KeyFixed 128-bit key, security comparable to AES-128
128-bit BlockBlock length of 128 bits, same as AES
32 RoundsUses 32 rounds of nonlinear iteration, high security
Localized DesignOptimized for Chinese application scenarios, seamlessly integrated with national cryptography algorithm system
Compliance Requirements: According to the Cryptography Law of the People's Republic of China and related industry regulations, cryptographic applications in critical sectors such as finance, government, and telecommunications should use national cryptography algorithms. If your application involves these sectors, SM4 should be prioritized over AES.

Encryption Mode Selection

SM4 supports multiple encryption modes, each with different security and performance characteristics:

CBC (Recommended)Cipher Block Chaining mode, high security, requires IV, suitable for most scenarios
ECB (Not Recommended)Electronic Codebook mode, no IV required, but low security, identical plaintext produces identical ciphertext
Security Warning: ECB mode has security vulnerabilities, identical plaintext blocks produce identical ciphertext blocks, making patterns easily identifiable by attackers. Production environments should use CBC mode, and ensure a different random IV is used for each encryption.

Application Scenarios

SM4 is widely used in China's critical information infrastructure and commercial cryptography sectors:

Financial IndustryData encryption and transaction protection for banks, securities, and insurance institutions
Government SystemsData encryption for e-government, electronic licenses, and government data exchange
TelecommunicationsData encryption and transmission protection for mobile communications and IoT devices
National Cryptography SSLNational cryptography SSL certificates (SM2-SM3-SM4 suite) use SM4 for symmetric encryption
File EncryptionEncrypted storage of sensitive files within government and enterprises
Database EncryptionEncrypt database fields and backup files

FAQ

Q: What's the difference between SM4 and AES?

A: Standard Origin: SM4 is a commercial cryptography standard released by China's State Cryptography Administration (2012), AES is a federal standard released by the U.S. NIST (2001). Key Length: SM4 only supports 128-bit keys, AES supports 128/192/256 bits. Algorithm Structure: SM4 is based on Feistel structure (32 rounds), AES is based on SPN structure (10/12/14 rounds). Security: SM4 has comparable security to AES-128, both with 2^128 complexity. Performance: AES performs better on platforms with hardware acceleration, SM4 has comparable performance in software implementations. Compliance: In China's critical sectors, SM4 complies with Cryptography Law requirements, AES does not. Recommendation: Use SM4 for critical sectors within China, use AES for international applications.

Q: Which scenarios require mandatory use of SM4?

A: According to the Cryptography Law of the People's Republic of China (effective January 1, 2020) and related industry regulations: Mandatory Use: Commercial cryptography products involving national security, national economy and people's livelihood, and social public interests must be certified by the State Cryptography Administration and use national cryptography algorithms (including SM4). Recommended Use: Critical sectors such as finance (banking, securities, insurance), government (e-government, electronic licenses), telecommunications (mobile communications, IoT), energy (electricity, petroleum), and transportation (railways, civil aviation). Optional Use: General commercial applications and personal applications can choose independently, but using national cryptography algorithms helps improve security and compliance. Note: Specific requirements are subject to the latest laws, regulations, and industry standards.

Q: Why does SM4 only have a 128-bit key length?

A: SM4's choice of a 128-bit key was based on balancing security and performance considerations. Sufficient Security: The breaking complexity of a 128-bit key is 2^128 (approximately 3.4×10^38), would take billions of years even using all computers globally. Performance Advantage: 128-bit keys perform better than 256-bit keys, with faster encryption speeds. International Standard: AES-128 is also a widely used standard, proving that 128-bit keys are sufficiently secure. Future Extension: If higher security is needed in the future, variants or upgraded versions of SM4 can be used. Practical Application: For the vast majority of application scenarios, SM4's 128-bit key already provides sufficient security.

Q: How to use SM4 in international applications?

A: Compatibility Considerations: SM4 is primarily used in China with limited international support. If the application needs to be internationalized, it's recommended to support both SM4 and AES. Dual Algorithm Approach: 1) Negotiation Mechanism: Client and server negotiate the algorithm to use (SM4 within China, AES abroad). 2) Dual Encryption: Use both SM4 and AES encryption simultaneously to ensure decryption both domestically and internationally. 3) Algorithm Identification: Identify the algorithm used in the data, and select the algorithm based on the identifier during decryption. Library Support: OpenSSL 1.1.1+ supports SM4, GmSSL is a specialized national cryptography algorithm library.

Q: What's the relationship between SM4, SM2, and SM3?

A: SM4, SM2, and SM3 are three core components of the national cryptography algorithm system, often used together. SM4: Symmetric encryption algorithm, used for data encryption, fast speed, suitable for large amounts of data. SM2: Asymmetric encryption and digital signature algorithm, used for key exchange and signing, high security but slower speed. SM3: Hash algorithm, used for data integrity verification and message digests. Combined Use: Typical workflow is to use SM2 to exchange SM4 keys, use SM4 to encrypt data, use SM3 to verify integrity, and use SM2 for signing. National Cryptography Suite: SM2-SM3-SM4 is a complete national cryptography algorithm suite, similar to the RSA-SHA256-AES suite. Application: National cryptography SSL certificates use the SM2-SM3-SM4 suite, replacing the traditional RSA-SHA256-AES suite.

Q: How to verify the correctness of SM4 implementation?

A: Standard Test Vectors: The GM/T 0002-2012 standard provides official test vectors. For example, using specific keys and plaintext, SM4 should produce specific ciphertext. Comparison Tools: Use multiple independent implementations (such as OpenSSL, GmSSL, this tool) to encrypt the same data and compare results for consistency. Decryption Verification: Decrypt immediately after encryption to check if the original data can be recovered. Certified Products: If used for commercial cryptography products, use cryptographic modules certified by the State Cryptography Administration. Open Source Implementation: GmSSL (GitHub) is an authoritative open-source implementation of national cryptography algorithms and can be used as a reference.

Use Cases

Recommended: Financial Industry Data Encryption

Data encryption for financial institutions such as banks, securities, and insurance should use national cryptography algorithms. Typical applications include: transaction data encryption, customer information protection, database field encryption. SM4-CBC mode is recommended, combined with SM3 for integrity verification, and SM2 for key exchange and digital signatures. This complies with requirements from regulatory bodies such as the People's Bank of China and the China Banking and Insurance Regulatory Commission.

Recommended Configuration:
  • ✅ SM4-CBC (national standard, recommended for finance)
  • ✅ SM2 (key exchange and signing)
  • ✅ SM3 (integrity verification)
  • ✅ Use cryptographic modules certified by national cryptography
  • 💡 Consider dual algorithm approach (SM4 + AES) for improved compatibility
Recommended: Government System Data Encryption

E-government and government data exchange platforms should use national cryptography algorithms to protect data confidentiality. Use SM4-CBC to encrypt sensitive data, ensuring data security during storage and transmission. Combined with SM2 signatures and SM3 hashing, build a complete security system.

Recommended Configuration:
  • ✅ SM4-CBC (data encryption)
  • ✅ SM2 (digital signatures)
  • ✅ SM3 (integrity verification)
  • 💡 Follow 'Technical Requirements for Cryptographic Applications in Government Information Systems'
Recommended: National Cryptography SSL/TLS Communications

National cryptography SSL/TLS uses the SM2-SM3-SM4 suite, replacing the traditional RSA-SHA256-AES suite. SM4 is used for session key encryption, protecting the confidentiality of transmitted data. Applicable to government websites, financial institutions, critical information infrastructure, and other scenarios that need to comply with Cryptography Law requirements.

Recommended Configuration:
  • ✅ SM2-SM3-SM4 (national cryptography SSL standard suite)
  • ✅ Dual certificate approach (national cryptography + RSA, compatible domestically and internationally)
  • ✅ Use browsers and servers that support national cryptography
  • 💡 Refer to 'SSL VPN Technical Specification' (GM/T 0024-2014)
Recommended: File and Database Encryption

Encryption of sensitive files and database fields within government and enterprises should use SM4. Use SM4-CBC mode to encrypt files or database fields, with keys managed through Key Management Services (KMS). Use a different random IV for each encryption; the IV can be stored in the file header or database. For classified files, SM2 digital signatures should be combined to ensure trustworthy file sources.

Recommended Configuration:
  • ✅ SM4-CBC (recommended)
  • ✅ Use national cryptography KMS to manage keys
  • ✅ Use a different IV for each encryption
  • ✅ Combined with SM2 signatures (highest security)
  • 💡 Regularly rotate keys
Recommended: IoT Device Communication Encryption

Scenarios such as telecommunications operators, smart homes, and industrial IoT should use national cryptography algorithms. SM4 is suitable for resource-constrained IoT devices, with better performance than AES-256 and security comparable to AES-128. Use SM4-CBC to encrypt device communication data, combined with SM2 for device authentication, and SM3 to verify firmware integrity.

Recommended Configuration:
  • ✅ SM4-CBC (lightweight encryption)
  • ✅ SM2 (device authentication)
  • ✅ SM3 (firmware integrity)
  • 💡 Refer to 'Technical Requirements for Cryptographic Applications in IoT'
Recommended: Cloud Storage File Encryption

Sensitive files uploaded to cloud storage should be encrypted with SM4 on the client side before upload to ensure cloud service providers cannot access plaintext. Use SM4-CBC to encrypt files, with keys managed by the client (not uploaded to the cloud). For applications that need to be internationalized, both SM4 and AES can be supported simultaneously, selecting algorithms based on user region.

Recommended Configuration:
  • ✅ SM4-CBC (national standard)
  • ✅ Client-side encryption, keys not uploaded
  • ✅ Consider dual algorithm approach (SM4 + AES)
  • 💡 Backup keys; losing keys means data cannot be recovered

Best Practice Recommendations

  • In critical sectors such as finance, government, and telecommunications within China, SM4 should be prioritized to comply with Cryptography Law requirements.
  • If the application needs to be internationalized, it's recommended to support both SM4 and AES, selecting algorithms based on region or user.
  • Production environments should use CBC mode, avoid ECB mode, and use a different random IV for each encryption.
  • When using national cryptography algorithms, cryptographic modules certified by the State Cryptography Administration should be selected to ensure compliance and security.
  • SM4 is typically used together with SM2 (key exchange, signing) and SM3 (integrity verification) to build a complete national cryptography security system.
  • Key management is crucial; use national cryptography KMS to manage keys, regularly rotate keys, and limit access permissions.

Discussion & Feedback

0 comments
Me