[openssl-users] Programmatic key conversion of PKCS#1 to #8

Matt Caswell matt at openssl.org
Fri Feb 16 17:49:13 UTC 2018

On 16/02/18 17:24, Gelareh Taban wrote:
> Hi all,
> I need to convert a Json Web Key (JWK) to PEM PKCS#8 format.
> I am using creating an RSA key using the parameters in JWK and then
> using i2d_RSAPublicKey() to  encode the RSA key to PEM PKCS#1. 
> Are there any OpenSSL functions that programmatically convert the key
> (both public and private) to PKCS#8? 

You can use PEM_write_bio_PrivateKey() for this purpose. You need to
have your RSA key in EVP_PKEY format first. So something like
(simplified to remove error handling):

EVP_PKEY *key = EVP_PKEY_new();
EVP_PKEY_assign_RSA(key, rsa);





More information about the openssl-users mailing list