How zyjnicemoe/sm-crypto-utils works
Project type and purpose
• This is a Java/Maven library (“sm-crypto-utils”) providing utility classes for the Chinese national cryptographic algorithms SM2, SM3, and SM4.
• It exposes a public API (SM2.java, SM3.java, SM4.java) and wraps BouncyCastle as its cryptographic provider.
File structure
• Top-level:
• pom.xml — Maven coordinates and dependencies
• build_release.sh, build_snapshots.sh — release pipeline scripts
• src/main/java/cn/zyjblogs/crypto:
• SmException.java — common exception type
• sm2/… — SM2 keypair generation, encrypt/decrypt, signature & verification classes
• sm3/SM3.java — digest/hash operations
• sm4/SM4.java — symmetric key gen, encrypt/decrypt operations
Review the README for insights
• Confirms SM2, SM3, SM4 usage examples.
• Notes reliance on BC (“BC库”) under the hood.
• Shows Maven dependency snippet—illustrates how clients integrate.
a. Main components:
• Client Application (any Java project that consumes the library)
• sm-crypto-utils Library API
– Package: crypto.sm2
– Package: crypto.sm3
– Package: crypto.sm4
– Common: SmException
• External Crypto Provider: BouncyCastle
• Build & Release Pipeline
– Maven (pom.xml)
– Shell scripts (build_release.sh, build_snapshots.sh)
b. Relationships & data flow:
1. Client invokes API methods (e.g., SM2.encrypt(), SM3.digest(), SM4.decrypt()).
2. API classes call into BouncyCastle provider classes for low-level crypto operations.
3. API returns results or throws SmException on errors.
4. Build scripts invoke Maven to compile, test, package, and publish snapshots/releases to a repository.
c. Architectural patterns & design principles:
• Modular packaging: separate packages for each algorithm.
• Utility/static-method pattern: no application server or stateful components.
• Exception abstraction: SmException wraps underlying provider errors.
• Dependency inversion: high-level API depends on BC through interfaces provided by the BouncyCastle library.
d. Technologies/frameworks/libraries:
• Java 8+
• Apache Maven
• BouncyCastle (bcprov)
• Shell scripting (bash) for CI/CD