3

I have a public key in the following (format-neutral; the type is specified by the DER bytes) format:

$ cat pubkey.der | openssl asn1parse -inform der -i
    0:d=0  hl=4 l= 290 cons: SEQUENCE
    4:d=1  hl=2 l=  13 cons:  SEQUENCE
    6:d=2  hl=2 l=   9 prim:   OBJECT            :rsaEncryption
   17:d=2  hl=2 l=   0 prim:   NULL
   19:d=1  hl=4 l= 271 prim:  BIT STRING

$ cat pubkey.der | openssl rsa -inform der -pubin -text Public-Key: (2048 bit) Modulus: 00:ac:f3:c2:c6:60:c2:9b:1e:db:fb:b6:32:67:45: 09:25:be:b0:d9:66:21:a0:80:ac:52:be:d4:59:1c: 7f:85:c0:45:ed:4e:85:69:55:80:a9:1e:36:94:93: 19:ce:30:8b:89:5d:1a:8e:9a:d6:7a:88:6a:1a:68: 6d:72:57:5e:11:a2:ec:9e:44:b7:64:06:6a:1c:d0: 81:b2:18:cb:a1:82:7f:ef:ad:ef:1a:61:52:46:54: d0:50:1f:73:14:ad:2c:8e:4c:d8:90:74:9a:f5:37: e7:54:91:3b:79:0a:2e:af:7e:f3:de:98:1c:3c:fd: d6:67:73:63:7b:10:7d:b7:77:04:ab:42:17:33:4d: 28:79:ed:4c:a1:96:71:94:32:bf:2d:49:d6:bd:b2: c5:26:42:ad:3e:f4:bb:8e:e8:70:1d:7f:cc:3b:a6: 04:6c:be:6f:1a:a2:40:c4:a5:ee:d5:83:87:44:a5: 90:22:c5:96:14:69:3c:ae:65:76:9c:45:41:4b:5f: 04:03:27:b6:74:a5:3b:c4:27:d4:83:7c:0a:18:b4: 5d:36:95:6f:9b:08:f4:14:37:8d:33:be:bd:e0:46: 11:89:9e:f9:5b:49:f7:9e:c6:2f:86:5e:96:83:5e: 47:9c:c0:3a:60:91:ea:41:98:7f:3e:85:a5:ab:73: b0:59 Exponent: 65537 (0x10001) writing RSA key -----BEGIN PUBLIC KEY----- MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArPPCxmDCmx7b+7YyZ0UJ Jb6w2WYhoICsUr7UWRx/hcBF7U6FaVWAqR42lJMZzjCLiV0ajprWeohqGmhtclde EaLsnkS3ZAZqHNCBshjLoYJ/763vGmFSRlTQUB9zFK0sjkzYkHSa9TfnVJE7eQou r37z3pgcPP3WZ3NjexB9t3cEq0IXM00oee1MoZZxlDK/LUnWvbLFJkKtPvS7juhw HX/MO6YEbL5vGqJAxKXu1YOHRKWQIsWWFGk8rmV2nEVBS18EAye2dKU7xCfUg3wK GLRdNpVvmwj0FDeNM7694EYRiZ75W0n3nsYvhl6Wg15HnMA6YJHqQZh/PoWlq3Ow WQIDAQAB -----END PUBLIC KEY-----

What is the technical name for this format? I keep wanting to call it PKCS#8, but I think that would be incorrect, since PKCS#8 is a private key format. What do we name the PKCS#8 equivalent DER format for public keys?

mpontillo
  • 151
  • 7

1 Answers1

2

As can be seen by RFC 5280 (X.509), this structure is the SubjectPublicKeyInfo. This field is formatted as follows:

SubjectPublicKeyInfo  ::=  SEQUENCE  {
     algorithm            AlgorithmIdentifier,
     subjectPublicKey     BIT STRING  }

The AlgorithmIdentifier is defined as follows:

AlgorithmIdentifier  ::=  SEQUENCE  {
     algorithm               OBJECT IDENTIFIER,
     parameters              ANY DEFINED BY algorithm OPTIONAL  }

The above two types define the format of the outer container in the ASN.1 in question (with the NULL value corresponding to the parameters field). The BIT STRING is an inner object defined by Appendix A.1.1 of PKCS #1 v2.1 as follows:

RSAPublicKey ::= SEQUENCE {
    modulus           INTEGER,  -- n
    publicExponent    INTEGER   -- e
}
mpontillo
  • 151
  • 7