OpenSSL "ans1parse" - RSA Public Key in ASN.1 Structure

Q

How to view the ASN.1 structure of an RSA public key using the OpenSSL "asn1parse" command?

✍: FYIcenter.com

A

You can use the OpenSSL "asn1parse" command to view the ASN.1 structure of an RSA public key as shown in the test below:

C:\Users\fyicenter>\local\openssl\openssl 
   pkey -in rsa_pri.key -pubout -out rsa_pub.key

C:\Users\fyicenter>\local\openssl\openssl 
   asn1parse -in rsa_pub.key -i
    0:d=0  hl=2 l=  92 cons: SEQUENCE
    2:d=1  hl=2 l=  13 cons:  SEQUENCE
    4:d=2  hl=2 l=   9 prim:   OBJECT            :rsaEncryption
   15:d=2  hl=2 l=   0 prim:   NULL
   17:d=1  hl=2 l=  75 prim:  BIT STRING
   
C:\Users\fyicenter>\local\openssl\openssl 
   asn1parse -in rsa_pub.key -strparse 17
    0:d=0  hl=2 l=  72 cons: SEQUENCE
    2:d=1  hl=2 l=  65 prim: INTEGER           :98872AF758AD6325645AA989ED59ABF2
AA4200F6DE59C1D5567A343B8852E32A9EA593559142A0EDD535916D03490EAF324C3E6A973A7161
E5D28E355E5E1E03
   69:d=1  hl=2 l=   3 prim: INTEGER           :010001
   
C:\Users\fyicenter>\local\openssl\openssl 
   pkey -pubin -in rsa_pub.key -text -noout
Public-Key: (512 bit)
Modulus:
    00:98:87:2a:f7:58:ad:63:25:64:5a:a9:89:ed:59:
    ab:f2:aa:42:00:f6:de:59:c1:d5:56:7a:34:3b:88:
    52:e3:2a:9e:a5:93:55:91:42:a0:ed:d5:35:91:6d:
    03:49:0e:af:32:4c:3e:6a:97:3a:71:61:e5:d2:8e:
    35:5e:5e:1e:03
Exponent: 65537 (0x10001)   

Note about the test:

  • A RSA public key is stored in an ASN.1 structure starting with root SEQUENCE, which includes a sub SEQUENCE and a BIT STRING.
  • The sub SEQUENCE contains the OID of the RSA algorithm and a NULL field.
  • The BIT STRING wraps a hidden SEQUENCE that has 2 INTEGER fields representing the RSA public components.

 

OpenSSL "ans1parse" - Configuration File for RSA Public Key

OpenSSL "ans1parse" - Configuration File for RSA Private Key

OpenSSL "ans1parse" Command

⇑⇑ OpenSSL Tutorials

2016-09-27, 5027👍, 0💬