How to extract a raw string from a dumpasn1 output?

172 views Asked by At

I own an Apple APNs p8 file, which is basically a PKCS#8 file containing a public key as well as a private key.

I basically need to extract the private key information from this file, to then sign a JWT.

DISCLAIMER: the following information matches a real key which has been revoked.

I started by generating an ASN1 file from my p8 file. Using the dumpasn1 tool, I get this output:

 2 SEQUENCE {
 3   INTEGER 0
 4   SEQUENCE {
 5     OBJECT IDENTIFIER ecPublicKey (1 2 840 10045 2 1)
 6     OBJECT IDENTIFIER prime256v1 (1 2 840 10045 3 1 7)
 7     }
 8   OCTET STRING, encapsulates {
 9     SEQUENCE {
10       INTEGER 1
11       OCTET STRING
12         B8 89 CA 8C 12 AB AF 74 9E CA 11 D4 D8 36 B8 28
13         D1 99 4F 8D B3 72 52 49 3D 85 44 02 08 05 64 1E
14       [0] {
15         OBJECT IDENTIFIER prime256v1 (1 2 840 10045 3 1 7)
16         }
17       [1] {
18         BIT STRING
19           04 CD BB 86 D3 2C 4D 08 11 6A A4 D3 38 4E AE 1B
20           DF E3 EC E5 D4 6F 03 0D CF 39 CD 79 3C 2E E6 74
21           FA 93 54 10 F2 10 41 92 78 57 7D 87 72 55 F3 30
22           BE F4 CA 6F F0 89 55 24 B8 B6 84 89 9C 4A 08 B5
23           1A
24         }
25       }
26     }
27   }

As I understand it, the private key is represented by a byte array written in HEX format from line 19 to line 23.

I now want to convert this byte array into a raw string.

IMHO, a good starting point would be to determine the encoding of the original text these bytes come from... and that's where I'm stuck.

Are there some tools I can use to achieve my goal?

Thank you

0

There are 0 answers