Retrieve public key from DER encoded certificate

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Retrieve public key from DER encoded certificate

Eric Meadows-Jönsson
I have a DER encoded certificate that i decode to #'Certificate' with public_key:pkix_decode_cert(Cert, plain). From the certificate I retrieve #'SubjectPublicKeyInfo' which I pass to publick_key:pem_entry_decode/1 to get rsa_public_key() or dsa_public_key().

But this function call fails because pem_entry_decode/1 does not seem to expect #'SubjectPublicKeyInfo' to be already decoded. It already has the structure that it tries to decode to here https://github.com/erlang/otp/blob/382943f9a943eb4215a297f9445e21fb9b5c0633/lib/public_key/src/public_key.erl#L119-L120.

How should I retrieve rsa_public_key() | dsa_public_key() from a DER encoded certificate?

--
Eric Meadows-Jönsson

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Retrieve public key from DER encoded certificate

Martin Karlsson-2
Hi Eric,

> How should I retrieve rsa_public_key() | dsa_public_key() from a DER encoded
> certificate?

You should look into public_key:der_decode/2

To get a SubjectPublicKeyInfo to rsa_public_key() you need to do something like this:

{0, Res} = Info#'SubjectPublicKeyInfo'.subjectPublicKey,
public_key:der_decode('RSAPublicKey', Res).

We do something similar but do not work with certificates.

Hope this helps,

Cheers,
Martin





_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions