stdx.crypto.keys
Functionality Overview
The keys package provides asymmetric encryption and signature algorithms, including RSA and SM2 asymmetric encryption algorithms, as well as the ECDSA signature algorithm.
Using this package requires external dependencies on OpenSSL 3's crypto dynamic library files. Therefore, relevant tools must be installed before use.
-
For Linux operating systems, refer to the following methods:
- If the system's package manager supports installing the OpenSSL 3 development toolkit, you can install it this way. Ensure the system installation directory contains the dynamic library files
libcrypto.soandlibcrypto.so.3. For example, on Ubuntu 22.04, you can use the commandsudo apt install libssl-devto install the libssl-dev toolkit. - If installation via the above method is not possible, download the OpenSSL 3.x.x source code and compile/install the package manually. Ensure the installation directory contains
libcrypto.soandlibcrypto.so.3. Then, choose one of the following methods to ensure the system linker can locate these files:- If OpenSSL is not installed on the system, select direct installation to the system path during installation.
- For custom directory installations, add the directory containing these files to the environment variables
LD_LIBRARY_PATHandLIBRARY_PATH.
- If the system's package manager supports installing the OpenSSL 3 development toolkit, you can install it this way. Ensure the system installation directory contains the dynamic library files
-
For Windows operating systems, follow these steps:
- Download the OpenSSL 3.x.x source code and compile/install the x64 architecture package, or download and install a third-party precompiled OpenSSL 3.x.x package for developers.
- Ensure the installation directory contains the library files
libcrypto.dll.a(orlibcrypto.lib) andlibcrypto-3-x64.dll. - Add the directory path containing
libcrypto.dll.a(orlibcrypto.lib) to theLIBRARY_PATHenvironment variable, and add the directory path containinglibcrypto-3-x64.dllto thePATHenvironment variable.
-
For macOS operating systems, refer to the following methods:
- Use
brew install openssl@3to install, and ensure the system installation directory contains the dynamic library fileslibcrypto.dylibandlibcrypto.3.dylib. - If installation via the above method is not possible, download the OpenSSL 3.x.x source code and compile/install the package manually. Ensure the installation directory contains
libcrypto.dylibandlibcrypto.3.dylib. Then, choose one of the following methods to ensure the system linker can locate these files:- If OpenSSL is not installed on the system, select direct installation to the system path during installation.
- For custom directory installations, add the directory containing these files to the environment variables
DYLD_LIBRARY_PATHandLIBRARY_PATH.
- Use
-
For Android operating systems:
- Since Android ships with a stripped-down version of OpenSSL by default, some interfaces may throw exceptions due to missing symbols. Therefore, users need to compile and install a complete
OpenSSL 3.x.xversion themselves. - Download the
OpenSSL 3.x.xsource code and use Android NDK to cross-compile dynamic library files for the target architectures (currently onlyarm64-v8ais supported). Ensure the build artifacts includelibcrypto.soandlibcrypto.so.3. - Add the directory containing these files to the environment variables
LD_LIBRARY_PATH.
- Since Android ships with a stripped-down version of OpenSSL by default, some interfaces may throw exceptions due to missing symbols. Therefore, users need to compile and install a complete
-
For HarmonyOS operating systems:
- Due to system restrictions in
HarmonyOS6.0 and above,stdxcannot directly access the system's built-inOpenSSL, users need to compileOpenSSLdynamic libraries forHarmonyOSand package them into the application. - For compiling
OpenSSLforHarmonyOS, refer to OHOS Cangjie SDK Build Guide. - Package the compiled dynamic library files
libcrypto_openssl.z.soandlibssl_openssl.z.sointo the application and ensure they can be correctly loaded at runtime.
- Due to system restrictions in
Note:
If the OpenSSL 3 package is not installed or a lower version is installed, the program may fail to function and throw the related exception
CryptoException: Can not load openssl library or function xxx.
API List
Classes
| Class Name | Functionality |
|---|---|
| ECDSAPrivateKey | ECDSA private key class. |
| ECDSAPublicKey | ECDSA public key class. |
| GeneralPrivateKey | Implementation of generic private key parameter encryption/decryption functionality. |
| GeneralPublicKey | Implementation of generic public key parameter encryption/decryption functionality. |
| RSAPrivateKey | RSA private key class. |
| RSAPublicKey | RSA public key class. |
| SM2PrivateKey | SM2 private key class. |
| SM2PublicKey | SM2 public key class. |
Enums
| Enum Name | Functionality |
|---|---|
| Curve | The enum Curve is used to select the elliptic curve type for generating ECDSA keys. |
| PadOption | Used to set the padding mode for RSA. |
Structs
| Struct Name | Functionality |
|---|---|
| OAEPOption | Optimal Asymmetric Encryption Padding. |
| PSSOption | Probabilistic Signature Scheme. |