0

I am using RSA_public_encrypt function to send the encrypted data to socket. I am reading the public key from .PEM file using "pkey = PEM_read_PUBKEY(f, NULL, NULL, NULL);" function. 'pkey' retrieved from above function is of type EVP_PKEY* which I can not use in function RSA_public_encrypt. (RSA_public_encrypt uses RSA* type key)

How to convert EVP_PKEY *pkey to RSA *rsa?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Andrew
  • 71
  • 2
  • 5

1 Answers1

1

Use RSA *EVP_PKEY_get1_RSA(EVP_PKEY *pkey) to get RSA type key from EVP_PKEY.

Example:

EVP_PKEY    *evp;
RSA         *pubkey

evp = ...; /* some way to get the public key */
pubkey = EVP_PKEY_get1_RSA(evp);
if (pubkey == NULL) {
    /* error handling */
}
Paul Yang
  • 11
  • 1