cryptography - openssl - RSA public key from PEM to DER -


i confronted problem when translating rsa pub key using openssl, want public key in der format. here did:

  1. generate rsa key pair openssl genrsa -out alice.key 1024

  2. export public key my.key a) openssl rsa -in alice.pem -rsapublickey_out -out alice_pub.pem b) openssl rsa -in alice.pem -pubout -out alice_pub2.pem

the 2 approaches generate different footers in .pem: first 1 outputs --begin rsa public key ----, , second outputs -- begin public key ----

  1. when using openssl asn1parse analyze 2 public key pem files, openssl asn1 parse -inform pem -in alice_pub.pem, unexpected happened. alice_pub.pem, works good; alice_pub2.pem, openssl unable extract "n" , "e" parameters indicating have been "rsaencryption".

  2. openssl can transform second pem der, however, pem content incorrect...

pls let me know how solve problem. many thanks. issue can reproduced easily.

it's unclear mean when openssl can transform second pem der - openssl asn1parse can read both , output both der.

the output of -rsapublickey_out public key no additional wrapping, , when put through openssl asn1parse, following:

    0:d=0  hl=3 l= 137 cons: sequence     3:d=1  hl=3 l= 129 prim: integer           :...   135:d=1  hl=2 l=   3 prim: integer           :010001 

however output produced -pubout public key in x509 format, when put through openssl asn1parse, following output:

    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 

this format wraps public key (displayed undecoded bit string) indicator it's rsa public key (rsaencryption).

you can show details of encoded public key in -pubout output using -strparse option openssl asn1parse. in above output can see bit string @ offset 18, using:

openssl asn1parse -inform pem -in alice_pub2.pem -strparse 18 

you following:

    0:d=0  hl=3 l= 137 cons: sequence     3:d=1  hl=3 l= 129 prim: integer           :...   135:d=1  hl=2 l=   3 prim: integer           :010001 

in other words, same data raw rsa public key produced -rsapublickey_out option openssl rsa.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -