<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-family:"Arial","sans-serif"">I am having a problem reading a password protected private key file (.pem) using the OpenSSL library (programmatically).<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Arial","sans-serif"">I just get a NULL key returned.
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Arial","sans-serif"">I am using the OpenSSL 1.0.2a 19 Mar 2015 library in a Windows environment.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Times New Roman","serif""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Arial","sans-serif"">The code snippet as follows:</span><span style="font-family:"Times New Roman","serif""><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"Times New Roman","serif""> <o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:.5in;text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas;color:blue">char</span><span style="font-size:10.0pt;font-family:Consolas"> *pemFileName =
<span style="color:#A31515">"C:\\Work\\mypemfile.pem"</span>;<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas">      
<span style="color:blue">char</span> passwordBuffer[12];<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas">       strcpy(passwordBuffer,
<span style="color:#A31515">"pwd1234"</span>);<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas"><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas">       OpenSSL_add_all_algorithms();<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas">       BIO *bio_key = BIO_new( BIO_s_file() );<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas">       BIO_read_filename( bio_key, pemFileName );<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas">       EVP_PKEY *sigkey  = PEM_read_bio_PrivateKey( bio_key, NULL, NULL,(<span style="color:blue">void</span> *)passwordBuffer );<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"Times New Roman","serif""> <o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Arial","sans-serif"">pemFileName </span>
<span style="font-family:"Arial","sans-serif"">is the (correct) path to the private key file.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Arial","sans-serif""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Arial","sans-serif"">I did read that calling OpenSSL_add_all_algorithms() loads OpenSSL's table of algorithms and was a fix to this issue.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Arial","sans-serif"">In my case it has not helped.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Arial","sans-serif""> <br>
<br>
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Arial","sans-serif"">Thanks for any help in soliving this issue.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"Times New Roman","serif""><o:p> </o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">John Vollaro<o:p></o:p></p>
<p class="MsoNormal">Phone 860.221.0129<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<p><br>
This e-mail, including attachments, may include confidential and/or<br>
proprietary information, and may be used only by the person or entity<br>
to which it is addressed. If the reader of this e-mail is not the intended<br>
recipient or his or her authorized agent, the reader is hereby notified<br>
that any dissemination, distribution or copying of this e-mail is<br>
prohibited. If you have received this e-mail in error, please notify the<br>
sender by replying to this message and delete this e-mail immediately.</p></body>
</html>