<html><head></head><body><div class="ydp32fbd563yahoo-style-wrap" style="font-family:lucida console, sans-serif;font-size:13px;"><div><span><div style="margin:0;"><font size="2" face="Calibri,sans-serif"><span style="font-size:11pt;">Hello,</span></font></div><div style="margin:0;"><font size="2" face="Calibri,sans-serif"><span style="font-size:11pt;">I am
 working on a small homework which requires convert pvk private key to PKCS#8 
format. The code is based on 
OpenSSL 1.0.2.</span></font></div></span></div><span>
<div style="margin:0;"><font size="2" face="Calibri,sans-serif"><span style="font-size:11pt;"> </span></font></div>
<div style="margin:0;"><font size="2" face="Calibri,sans-serif"><span style="font-size:11pt;">I
 can get pvk private key components (Public exponent, modulus, prime1, 
prime2, exponent1, exponent2, coefficient, private exponent) properly, 
and convert to a valid
RSA format (<font face="Courier New">RSA_check_key()returns success</font>).</span></font></div>
<div style="margin:0;"><font size="2" face="Calibri,sans-serif"><span style="font-size:11pt;"> </span></font></div>
<div style="margin:0;"><font size="2" face="Calibri,sans-serif"><span style="font-size:11pt;">Now
 I need to convert the key in RSA format to EVP_PKEY, then to PKCS#8. I 
have tried the following functions, all of these functions return 0 
(failure) without any
further debugging information/clues:</span></font></div>
<div style="margin:0;"><font size="2" face="Calibri,sans-serif"><span style="font-size:11pt;"><font face="Courier New">EVP_PKEY_assign_RSA(pEvpkey, rsa);</font></span></font></div>
<div style="margin:0;"><font size="2" face="Calibri,sans-serif"><span style="font-size:11pt;"><font face="Courier New">EVP_PKEY_set1_RSA(pEvpkey, rsa);</font></span></font></div>
<div style="margin:0;"><font size="2" face="Calibri,sans-serif"><span style="font-size:11pt;"><font face="Courier New">PEM_write_bio_RSAPrivateKey (out, rsa, cipher, NULL, 0, NULL, NULL);</font></span></font></div>
<div style="margin:0;"><font size="2" face="Calibri,sans-serif"><span style="font-size:11pt;"><font face="Courier New">PEM_write_bio_PKCS8PrivateKey(out, pEvpkey, 0, 0, 0, 0, 0);</font></span></font></div>
<div style="margin:0;"><font size="2" face="Calibri,sans-serif"><span style="font-size:11pt;"><font face="Courier New"> </font></span></font></div>
<div style="margin:0;"><font size="2" face="Calibri,sans-serif"><span style="font-size:11pt;"><font face="Courier New">I
 did google searching, but have not figured out why the about functions 
failed (one posting mentions “export version” vs. domestic version??).</font></span></font></div>
<div style="margin:0;"><font size="2" face="Calibri,sans-serif"><span style="font-size:11pt;"><font face="Courier New"> </font></span></font></div>
</span><div><span><div style="margin:0;"><font size="2" face="Calibri,sans-serif"><span style="font-size:11pt;"><font face="Courier New">So,
 I’d like to get some help, 1. hopefully, with more debug information. 2. suggestion: based on OpenSSL 1.0.2, what are the correct function-chain to change pvk private key to PKCS#5?</font></span></font></div></span></div><div><span><div style="margin:0;"><font size="2" face="Calibri,sans-serif"><span style="font-size:11pt;"></span></font></div></span><br></div><div><font size="2"><font face="Courier New">Any suggestions, input are appreciated.</font></font></div><div><font size="2"><font face="Courier New">Xuan</font></font><br></div><span>
<div style="margin:0;"><font size="2" face="Calibri,sans-serif"><span style="font-size:11pt;"><font face="Courier New"> </font></span></font></div></span><div id="ydp32fbd563yiv7843456459"><div><div class="ydp32fbd563yiv7843456459ydpa46777aayahoo-style-wrap" style="font-family:lucida console, sans-serif;font-size:13px;"></div></div></div></div></body></html>