<div dir="ltr">Works beautifully. Thanks very much Matt!</div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Feb 16, 2018 at 11:49 AM, Matt Caswell <span dir="ltr"><<a href="mailto:matt@openssl.org" target="_blank">matt@openssl.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
<br>
On 16/02/18 17:24, Gelareh Taban wrote:<br>
> Hi all,<br>
><br>
> I need to convert a Json Web Key (JWK) to PEM PKCS#8 format.<br>
><br>
> I am using creating an RSA key using the parameters in JWK and then<br>
> using i2d_RSAPublicKey() to  encode the RSA key to PEM PKCS#1. <br>
><br>
> Are there any OpenSSL functions that programmatically convert the key<br>
> (both public and private) to PKCS#8? <br>
<br>
</span>You can use PEM_write_bio_PrivateKey() for this purpose. You need to<br>
have your RSA key in EVP_PKEY format first. So something like<br>
(simplified to remove error handling):<br>
<br>
EVP_PKEY *key = EVP_PKEY_new();<br>
EVP_PKEY_assign_RSA(key, rsa);<br>
<br>
<a href="https://www.openssl.org/docs/man1.1.0/crypto/PEM_write_bio_PrivateKey.html" rel="noreferrer" target="_blank">https://www.openssl.org/docs/<wbr>man1.1.0/crypto/PEM_write_bio_<wbr>PrivateKey.html</a><br>
<br>
<a href="https://www.openssl.org/docs/man1.1.0/crypto/EVP_PKEY_new.html" rel="noreferrer" target="_blank">https://www.openssl.org/docs/<wbr>man1.1.0/crypto/EVP_PKEY_new.<wbr>html</a><br>
<br>
<a href="https://www.openssl.org/docs/man1.1.0/crypto/EVP_PKEY_assign_RSA.html" rel="noreferrer" target="_blank">https://www.openssl.org/docs/<wbr>man1.1.0/crypto/EVP_PKEY_<wbr>assign_RSA.html</a><br>
<span class="HOEnZb"><font color="#888888"><br>
Matt<br>
<br>
--<br>
openssl-users mailing list<br>
To unsubscribe: <a href="https://mta.openssl.org/mailman/listinfo/openssl-users" rel="noreferrer" target="_blank">https://mta.openssl.org/<wbr>mailman/listinfo/openssl-users</a><br>
</font></span></blockquote></div><br></div>