A PEM file is simply a DER file that's been Base64 encoded. To convert from one to the other you can use openssl
with the -inform
and -outform
arguments. Each one takes one of PEM
, DER
or NET
(a dated Netscape format, which you can ignore).
You can change a key from one format to the other with the openssl rsa
command (assuming it's an RSA key, of course):
$ openssl rsa -pubin -inform PEM -in <filename of key in PEM format> -outform DER -out <filename of key in DER format>
writing RSA key
You can then view the ASN.1 encoding of that file with:
$ openssl asn1parse -inform DER -in <filename of DER file>
0:d=0 hl=3 l= 159 cons: SEQUENCE
3:d=1 hl=2 l= 13 cons: SEQUENCE
5:d=2 hl=2 l= 9 prim: OBJECT :rsaEncryption
16:d=2 hl=2 l= 0 prim: NULL
18:d=1 hl=3 l= 141 prim: BIT STRING
Of course, this is of no use to you if your key is not an RSA key, but as your question doesn't stipulate what type of key it is, I've guessed :-)