<div dir="ltr"><div style="color:rgb(33,33,33);font-size:13px">Hi,</div><div style="color:rgb(33,33,33);font-size:13px"><br></div><div style="color:rgb(33,33,33);font-size:13px"><div>I have a `Certificates.p12` file that I wish to convert to a `certificates.pem` containing an unencrypted private key in PKCS#1 format. I have previously been able to do this by running:</div><div><br></div><div><font face="monospace">    openssl pkcs12 -in Certificates.p12 -out certificates.pem -nodes -clcerts</font></div><div><br></div><div>The resulting `certificates.pem` file has a `PRIVATE KEY` PEM block, as expected. However, <a href="https://github.com/sideshow/apns2/blob/master/certificate/certificate.go#L80" target="_blank">the library I'm using</a> does not understand this PEM block, because it expects it to be a PKCS#1 private key. The ASN.1 structure of a PKCS#1 private key is defined by <a href="https://tools.ietf.org/html/rfc3447#appendix-A.1.2" target="_blank">RFC 3447</a> as:</div><div><br></div><div><font face="monospace">    RSAPrivateKey ::= SEQUENCE {</font></div><div><font face="monospace">        version           Version,</font></div><div><font face="monospace">        modulus           INTEGER,  -- n</font></div><div><font face="monospace">        publicExponent    INTEGER,  -- e</font></div><div><font face="monospace">        privateExponent   INTEGER,  -- d</font></div><div><font face="monospace">        prime1            INTEGER,  -- p</font></div><div><font face="monospace">        prime2            INTEGER,  -- q</font></div><div><font face="monospace">        exponent1         INTEGER,  -- d mod (p-1)</font></div><div><font face="monospace">        exponent2         INTEGER,  -- d mod (q-1)</font></div><div><font face="monospace">        coefficient       INTEGER,  -- (inverse of q) mod p</font></div><div><font face="monospace">        otherPrimeInfos   OtherPrimeInfos OPTIONAL</font></div><div><font face="monospace">    }</font></div><div><br></div><div>The bad private key block in my `certificates.pem` does not have this PKCS#1 structure! Instead, its ASN.1 structure looks like this:</div><div><br></div><div><font face="monospace">    $ openssl asn1parse -i -in badprivatekey.pem</font></div><div><font face="monospace">        0:d=0  hl=4 l=1212 cons: SEQUENCE</font></div><div><font face="monospace">        4:d=1  hl=2 l=   1 prim:  INTEGER           :00</font></div><div><font face="monospace">        7:d=1  hl=2 l=  13 cons:  SEQUENCE</font></div><div><font face="monospace">        9:d=2  hl=2 l=   9 prim:   OBJECT            :rsaEncryption</font></div><div><font face="monospace">       20:d=2  hl=2 l=   0 prim:   NULL</font></div><div><font face="monospace">       22:d=1  hl=4 l=1190 prim:  OCTET STRING      [HEX DUMP]:308204A...very long hex...</font></div><div><br></div><div>What is the above format? <a href="https://wiki.openssl.org/index.php/Manual:Pkcs12(1)" target="_blank">The documentation for `openssl pkcs12`</a> only vaguely says that its output is "written in PEM format." I need a stronger guarantee that the private key PEM block is in PKCS#1 format.</div><div><br></div><div>The strange thing is that `openssl rsa` understands the strange format of the "bad" private key, and can convert it to the right PKCS#1 structure with:</div><div><br></div><div><font face="monospace">    openssl rsa -in badprivatekey.pem -out goodprivatekey.pem</font></div><div><br></div><div>Although `openssl rsa` understands the input file, the tool seems unable to tell me _why_, i.e. what the format of the input file is.</div><div><br></div><div>What is the output format of `openssl pkcs12`? Specifically what is the format of its private key block? How do I make `openssl pkcs12` output a correct PKCS#1 private key?</div></div><div style="color:rgb(33,33,33);font-size:13px"><br></div><div style="color:rgb(33,33,33);font-size:13px">Thanks,</div><div style="color:rgb(33,33,33);font-size:13px">Jim</div></div>