Problem using PKI private key file

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Problem using PKI private key file

Brian Modra
I have to use PKI private key and its associated certificate. But I am having trouble reading the private key and using it.

The following is copied from my terminal:

$ erl
Erlang/OTP 20 [erts-9.1] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:10] [kernel-poll:false]

Eshell V9.1  (abort with ^G)
1> {ok, PrivPemBin} = file:read_file("").
{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: "...>>}
2> [PrivKeyEntry] =  public_key:pem_decode(PrivPemBin).

3> PrivKey = public_key:pem_entry_decode(PrivKeyEntry).

4> Encrypted = public_key:encrypt_private(<<"Hello World">>, PrivKey).
** exception error: no function clause matching public_key:encrypt_private(<<"Hello World">>,
                                                                           []) (public_key.erl, line 389)

Notice that the key shows {'PrivateKeyInfo_privateKeyAlgorithm',{1,2,840,113549,1,1,1},{asn1_OPENTYPE,<<5,0>>}},
rather than something more recognisable like 'RSAPrivateKey'...

Is this telling me the algorithm is not supported, or am I just not calling the right functions?

The header of the PEM file looks as so:

Bag Attributes
    localKeyID: A1 77 37 C0 83 09 CF E8 19 C9 C3 DD A7 56 79 28 DD 56 C6 01
Key Attributes: <No Attributes>
MIIEvgIB...  [trimmed out obviously]

... which I think is telling me that the PK is a PKCS#8 ?
(It was converted from a p12 file from an external source, using openssl).

Brian Modra  +61 4552 8 4772
26 Valley Drive, Caboolture, QLD 4510,  Australia

erlang-questions mailing list
[hidden email]