1

How can I convert the following public key to binary format? It's needed for a C program to verify an SSL public key. The file must be 256 bytes. I tried some online code but had no luck there.

-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAumNhA2fKXNflHwmmkZs9
VMV8vxlZrl+0kWHS89y0qJLJorea2YuHHiafkdtlu+M1M6y+J6REs8A/ufGwQyQ6
5Z64k8WwBnJN4NQjNhRPTB6jTvHqer63luHs5I76jLdRsQFXtQiDBK5cW0+k1xCm
ka6RT7EcJMaUgHy3ixxMpZlgFp0HTTHC7My92S5H7CARDaVcNkWf6RF9va3Ez+/b
ZwAcDvtojE+CKm2f5Az28TkEI/hnDXqGV+7xUkF7o/MGzUXrcY21Lj7qx3VGxPuJ
WthNffSu7Az7WfCyfMcy5DKz9zBRA82zWToMlsjsxdIJIChXJvGhOOF61b+X5ZMG
TQIDAQAB
-----END PUBLIC KEY-----

1 Answer 1

1

Assuming you have the key in the format that you posted in a file on your system (e.g. pubkey.pem), you can run the following openssl command to extract the components of the RSA key:

openssl rsa -noout -text -inform PEM -in pubkey.pem -pubin

This produces:

Public-Key: (2048 bit)
Modulus:
    00:ba:63:61:03:67:ca:5c:d7:e5:1f:09:a6:91:9b:
    3d:54:c5:7c:bf:19:59:ae:5f:b4:91:61:d2:f3:dc:
    b4:a8:92:c9:a2:b7:9a:d9:8b:87:1e:26:9f:91:db:
    65:bb:e3:35:33:ac:be:27:a4:44:b3:c0:3f:b9:f1:
    b0:43:24:3a:e5:9e:b8:93:c5:b0:06:72:4d:e0:d4:
    23:36:14:4f:4c:1e:a3:4e:f1:ea:7a:be:b7:96:e1:
    ec:e4:8e:fa:8c:b7:51:b1:01:57:b5:08:83:04:ae:
    5c:5b:4f:a4:d7:10:a6:91:ae:91:4f:b1:1c:24:c6:
    94:80:7c:b7:8b:1c:4c:a5:99:60:16:9d:07:4d:31:
    c2:ec:cc:bd:d9:2e:47:ec:20:11:0d:a5:5c:36:45:
    9f:e9:11:7d:bd:ad:c4:cf:ef:db:67:00:1c:0e:fb:
    68:8c:4f:82:2a:6d:9f:e4:0c:f6:f1:39:04:23:f8:
    67:0d:7a:86:57:ee:f1:52:41:7b:a3:f3:06:cd:45:
    eb:71:8d:b5:2e:3e:ea:c7:75:46:c4:fb:89:5a:d8:
    4d:7d:f4:ae:ec:0c:fb:59:f0:b2:7c:c7:32:e4:32:
    b3:f7:30:51:03:cd:b3:59:3a:0c:96:c8:ec:c5:d2:
    09:20:28:57:26:f1:a1:38:e1:7a:d5:bf:97:e5:93:
    06:4d
Exponent: 65537 (0x10001)
3
  • Thank you bro,i tried with this code but its size is 257 byte, whats correct method ?
    – Bumblebeey
    Jun 23, 2023 at 14:14
  • openssl rsa -noout -text -inform PEM -in pubkey.pem -pubin | grep -v 'Modulus' | tr -d '[:space:]:') | xxd -r -p > verify.bin
    – Bumblebeey
    Jun 23, 2023 at 14:19
  • 1
    You can disregard the first bye (00) (see crypto.stackexchange.com/questions/30608/… for some interesting reading on this). Then you have the 256 byte modulus (i.e. 2048 bits).
    – mti2935
    Jun 23, 2023 at 14:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .