How to encrypt with RSA programmatically
OpenSSL 3.0 provides the following APIs for RSA encryption:
- A legacy API with the
RSA_prefix and theRSA_public_encrypt()function. This API has been deprecated since OpenSSL 3.0, so we are not going to use it. - The
EVP_PKEYAPI, particularly theEVP_PKEY_encrypt()function. We are going to use this API. - The
EVP_SealAPI. This is a hybrid encryption API that generates a session key, encrypts the session key with RSA, and then encrypts the user data with the session key. This API contains theEVP_SealInit(),EVP_SealUpdate(), andEVP_SealFinal()functions, which work similarly toEVP_EncryptInit(),EVP_EncryptUpdate(), andEVP_EncryptFinal().EVP_SealUpdate()is just#defineforEVP_EncryptUpdate(). There are also the correspondingEVP_Openfunctions for decrypting the seals –EVP_OpenInit(),EVP_OpenUpdate(), andEVP_OpenFinal(). Unfortunately, theEVP_SealAPI is rather inflexible. It supports only RSA encryption of...