crypto.digest Package

Function Description

The digest package provides common message digest algorithms, including MD5, SHA1, SHA224, SHA256, SHA384, SHA512, HMAC, and SM3.

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
HMACSpecifies the HMAC digest algorithm.
MD5Specifies the MD5 digest algorithm.
SHA1Specifies the SHA1 digest algorithm.
SHA224Specifies the SHA224 digest algorithm.
SHA256Specifies the SHA256 digest algorithm.
SHA384Specifies the SHA384 digest algorithm.
SHA512Specifies the SHA512 digest algorithm.
SM3SM3 digest algorithm.

Struct

NameDescription
HashTypeSpecifies the digest algorithm type.

Exception Class

NameDescription
CryptoExceptionSpecifies the exception class of the crypto package.