net.tls Package
Function Description
The TLS package provides secure communications over a computer network with its capabilities such as creating TLS servers, performing TLS handshakes based on protocols, sending and receiving encrypted data, and restoring TLS sessions.
This package supports TLS 1.2 and TLS 1.3.
This package depends on the SSL
and crypto
dynamic library files of OpenSSL 3
. Therefore, related tools must be installed in advance.
- 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 thelibssl.so
,libssl.so.3
,libcrypto.so
, andlibcrypto.so.3
dynamic library files. For example, onUbuntu 22.04
, run thesudo apt install libssl-dev
command to install thelibssl-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 thelibssl.so
,libssl.so.3
,libcrypto.so
, andlibcrypto.so.3
dynamic library files. Then, use either of the following methods to ensure that the system linker can find these files:- Install OpenSSL in the system path if it has not been installed in the system.
- Set the directory where the OpenSSL development tool package files are located to the environment variables
LD_LIBRARY_PATH
andLIBRARY_PATH
if OpenSSL is installed in a user-defined directory.
- Install the
- 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 theOpenSSL 3.*x*.*x*
software package precompiled by a third party for developers. - Ensure that the installation directory contains the
libssl.dll.a
(orlibssl.lib
),libssl-3-x64.dll
,libcrypto.dll.a
(orlibcrypto.lib
), andlibcrypto-3-x64.dll
library files. - Set the directory containing
libssl.dll.a
(orlibssl.lib
) andlibcrypto.dll.a
(orlibcrypto.lib
) to the environment variableLIBRARY_PATH
, and the directory containinglibssl-3-x64.dll
andlibcrypto-3-x64.dll
to the environment variablePATH
.
- Download and install the
- For
macOS
, perform the following operations:- Run the
brew install openssl@3
command to install OpenSSL, and ensure that the system installation directory contains thelibcrypto.dylib
andlibcrypto.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 thelibcrypto.dylib
andlibcrypto.3.dylib
dynamic library files. Then, use either of the following methods to ensure that the system linker can find these files:- Install OpenSSL in the system path if it has not been installed in the system.
- Set the directory where the OpenSSL development tool package files are located to the environment variables
DYLD_LIBRARY_PATH
andLIBRARY_PATH
if OpenSSL is installed in a user-defined directory.
- Run the
Note:
If
OpenSSL 3
is not installed or an earlier version is installed, the program may fail to work with the following exception thrown: TlsException: Can not load openssl library or function xxx.
API List
Class
Name | Description |
---|---|
TlsSessionContext | The server enables the session feature to restore sessions and stores sessions for client authentication. |
TlsSocket | Creates an encrypted transmission channel between the client and server. |
Enumeration
Name | Description |
---|---|
CertificateVerifyMode | Certificate authentication mode. |
SignatureAlgorithm | Specifies the signature algorithm type. The signature algorithm is used to ensure the identity authentication, integrity, and authenticity of transmitted data. |
SignatureSchemeType | Specifies the encryption algorithm type, which is used to protect the security and privacy of network communication. |
SignatureType | Specifies the signature algorithm type, which is used for authenticity authentication. |
TlsClientIdentificationMode | Specifies the mode for the server to authenticate the client certificate. |
TlsVersion | Specifies the TLS protocol version. |
Struct
Name | Description |
---|---|
CipherSuite | Specifies the cipher suite in TLS. |
TlsClientConfig | Specifies the client configuration. |
TlsServerConfig | Specifies the server configuration. |
TlsSession | After the TLS handshake with the client is successful, a session is generated. If the connection is lost due to some reasons, the client can reuse the session by using the session ID and skip the handshake process. |
Exception Class
Name | Description |
---|---|
TlsException | Indicates the exception type thrown when an error occurs during TLS processing. |