Programmatic key conversion of PKCS#1 to #8

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Programmatic key conversion of PKCS#1 to #8

Gelareh Taban
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? 

Thanks!

--
openssl-users mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-users
Reply | Threaded
Open this post in threaded view
|

Re: Programmatic key conversion of PKCS#1 to #8

Matt Caswell-2


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);

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

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

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

Matt

--
openssl-users mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-users
Reply | Threaded
Open this post in threaded view
|

Re: Programmatic key conversion of PKCS#1 to #8

Gelareh Taban
Works beautifully. Thanks very much Matt!

On Fri, Feb 16, 2018 at 11:49 AM, Matt Caswell <[hidden email]> wrote:


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);

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

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

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

Matt

--
openssl-users mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-users


--
openssl-users mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-users