<div dir="ltr"><div><div><div>I have to use PKI private key and its associated certificate. But I am having trouble reading the private key and using it.<br><br>The following is copied from my terminal:<br><br>$ erl<br>Erlang/OTP 20 [erts-9.1] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:10] [kernel-poll:false]<br><br>Eshell V9.1  (abort with ^G)<br>1> {ok, PrivPemBin} = file:read_file("test.pk.pem").<br>{ok,<<"Bag Attributes\n    localKeyID: A1 77 37 C0 83 09 CF E8 19 C9 C3 DD A7 56 79 28 DD 56 C6 01 \nKey Attributes: "...>>}<br>2> [PrivKeyEntry] =  public_key:pem_decode(PrivPemBin).<br>[{'PrivateKeyInfo',<<48,130,4,190,2,1,0,48,13,6,9,42,134,...>>,<br>                   not_encrypted}]<br><br>3> PrivKey = public_key:pem_entry_decode(PrivKeyEntry).<br>{'PrivateKeyInfo',v1,<br>                  {'PrivateKeyInfo_privateKeyAlgorithm',{1,2,840,113549,1,1,1},<br>                                                        {asn1_OPENTYPE,<<5,0>>}},<br>                  <<48,130,4,164,2,1,0,2,130,1,1,0,174,64,216,53,107,61,116,...>>,<br>                  asn1_NOVALUE}<br><br>4> Encrypted = public_key:encrypt_private(<<"Hello World">>, PrivKey).<br>** exception error: no function clause matching public_key:encrypt_private(<<"Hello World">>,<br>                                                                           {'PrivateKeyInfo',v1, <br>                                                                                             {'PrivateKeyInfo_privateKeyAlgorithm',{1,2,840,113549,1,1,1},<br>                                                                                                                                   {asn1_OPENTYPE,<<5,0>>}},<br>                                                                                             <<48,130,4,164,2,1,0,2,130,1,1,0,174,64,216,53,107,61,116,...>>,<br>                                                                                             asn1_NOVALUE},<br>                                                                           []) (public_key.erl, line 389)<br><br><br>Notice that the key shows {'PrivateKeyInfo_privateKeyAlgorithm',{1,2,840,113549,1,1,1},{asn1_OPENTYPE,<<5,0>>}},<br>rather than something more recognisable like 'RSAPrivateKey'...<br><br><br>Is this telling me the algorithm is not supported, or am I just not calling the right functions?<br><br></div>The header of the PEM file looks as so:<br><br>Bag Attributes<br>    localKeyID: A1 77 37 C0 83 09 CF E8 19 C9 C3 DD A7 56 79 28 DD 56 C6 01 <br>Key Attributes: <No Attributes><br>-----BEGIN PRIVATE KEY-----<br>MIIEvgIB...  [trimmed out obviously]<br>-----END PRIVATE KEY-----<br><br></div>... which I think is telling me that the PK is a PKCS#8 ?<br></div>(It was converted from a p12 file from an external source, using openssl).<br><div><div><div><br>--<br>Brian Modra  +61 4552 8 4772<br>26 Valley Drive, Caboolture, QLD 4510,  Australia</div></div></div></div>