简体   繁体   中英

How to do RSA public key encryption using OpenSSL EVP routines?

I am using the EVP high-level functions in OpenSSL . I haven't found any examples online showing how to use these functions (eg EVP_EncryptInit_ex() , EVP_EncryptUpdate() , EVP_EncryptFinal_ex() ) to encrypt data using an RSA public key. Specifically, I do not see a EVP_CIPHER type that matches RSA, similar to what you see for AES like: const EVP_CIPHER *EVP_aes_128_cbc(void); in evp.h . I think one for RSA is required to initialize EVP for encryption using that method.

Can anyone help me understand how to use an RSA existing key to encrypt data using OpenSSL's EVP routines? Examples would be extremely helpful.

To do asymmetric encryption you need to use different EVP routines than for symmetric crypto. In particular see the EVP_PKEY_encrypt() function. The man page is here, and it contains an example.

https://www.openssl.org/docs/man1.1.0/crypto/EVP_PKEY_encrypt.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM