crypto.keys Package

Function Description

The keys package provides asymmetric encryption and signature algorithms, including RSA and SM2 asymmetric encryption algorithms and the ECDSA signature algorithm.

This package depends on the crypto dynamic library file of OpenSSL 3. Therefore, Related tools must be installed before using this package.

  • For Linux, perform the following operations:

    • Install the OpenSSL 3 development tool package using the package management tool of the system if the tool supports the installation, and ensure that the system installation directory contains the libcrypto.so and libcrypto.so.3 dynamic library files. For example, on Ubuntu 22.04, run the sudo apt install libssl-dev command to install the libssl-dev tool package.
    • Download and install the OpenSSL 3.x.x source code compilation software package if the preceding method fails, and ensure that the installation directory contains the libcrypto.so and libcrypto.so.3 dynamic library files. Then, use either of the following methods to ensure that the system linker can find these files:
      • Install the software in a system directory if OpenSSL has not been installed.
      • Set the directory containing these files to the environment variables LD_LIBRARY_PATH and LIBRARY_PATH if the software is installed in a user-defined directory.
  • For Windows, perform the following operations:

    • Download and install the OpenSSL 3.x.x source code compilation software package for the x64 architecture, or download and install the OpenSSL 3.x.x software package precompiled by a third party for developers.
    • Ensure that the installation directory contains the libcrypto.dll.a (or libcrypto.lib) and libcrypto-3-x64.dll library files.
    • Set the directory containing the libcrypto.dll.a (or libcrypto.lib) to the environment variable LIBRARY_PATH, and the directory containing libcrypto-3-x64.dll to the environment variable PATH.
  • For macOS, perform the following operations:

    • Run the brew install openssl@3 command to install OpenSSL, and ensure that the system installation directory contains the libcrypto.dylib and libcrypto.3.dylib dynamic library files.
    • Download and install the OpenSSL 3.x.x source code compilation software package if the preceding method fails, and ensure that the installation directory contains the libcrypto.dylib and libcrypto.3.dylib dynamic library files. Then, use either of the following methods to ensure that the system linker can find these files:
      • Install the software in a system directory if OpenSSL has not been installed.
      • Set the directory containing these files to the environment variables DYLD_LIBRARY_PATH and LIBRARY_PATH.

Note:

If OpenSSL 3 is not installed or an earlier version is installed, the program may fail to work with the following exception thrown: CryptoException: Can not load openssl library or function xxx.

API List

Class

NameDescription
ECDSAPrivateKeySpecifies the ECDSA private key class.
ECDSAPublicKeySpecifies the ECDSA public key class.
RSAPrivateKeySpecifies the RSA private key class.
RSAPublicKeySpecifies the RSA public key class.
SM2PrivateKeySpecifies the SM2 private key class.
SM2PublicKeySpecifies the SM2 public key class.

Enumeration

NameDescription
CurveThe enumeration type Curve is used to select the elliptic curve type when the ECDSA key is generated.
PadOptionSpecifies the padding mode of the RSA.

Structure

NameDescription
OAEPOptionSpecifies optimal asymmetric encryption padding
PSSOptionSpecifies a probabilistic signature scheme