0
$\begingroup$

Let's say I do this:

$ cat pubkey.txt
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCqGKukO1De7zhZj6+H0qtjTkVxwTCpvKe4eCZ0
FPqri0cb2JZfXJ/DgYSF6vUpwmJG8wVQZKjeGcjDOL5UlsuusFncCzWBQ7RKNUSesmQRMSGkVb1/
3j+skZ6UtW+5u09lHNsj6tQ51s1SPrCBkedbNf0Tp0GbMJDyR4e9T04ZZwIDAQAB
-----END PUBLIC KEY-----

$ openssl rsa -pubin -in pubkey.txt -text -noout
Public-Key: (1024 bit)
Modulus:
    00:aa:18:ab:a4:3b:50:de:ef:38:59:8f:af:87:d2:
    ab:63:4e:45:71:c1:30:a9:bc:a7:b8:78:26:74:14:
    fa:ab:8b:47:1b:d8:96:5f:5c:9f:c3:81:84:85:ea:
    f5:29:c2:62:46:f3:05:50:64:a8:de:19:c8:c3:38:
    be:54:96:cb:ae:b0:59:dc:0b:35:81:43:b4:4a:35:
    44:9e:b2:64:11:31:21:a4:55:bd:7f:de:3f:ac:91:
    9e:94:b5:6f:b9:bb:4f:65:1c:db:23:ea:d4:39:d6:
    cd:52:3e:b0:81:91:e7:5b:35:fd:13:a7:41:9b:30:
    90:f2:47:87:bd:4f:4e:19:67
Exponent: 65537 (0x10001)

How can I regenerate pubkey.txt when I only have the hexadecimal modulus in this format? Would there be any difference with a 2048 bit key?

00:aa:18:ab:a4:3b:50:de:ef:38:59:8f:af:87:d2:
ab:63:4e:45:71:c1:30:a9:bc:a7:b8:78:26:74:14:
fa:ab:8b:47:1b:d8:96:5f:5c:9f:c3:81:84:85:ea:
f5:29:c2:62:46:f3:05:50:64:a8:de:19:c8:c3:38:
be:54:96:cb:ae:b0:59:dc:0b:35:81:43:b4:4a:35:
44:9e:b2:64:11:31:21:a4:55:bd:7f:de:3f:ac:91:
9e:94:b5:6f:b9:bb:4f:65:1c:db:23:ea:d4:39:d6:
cd:52:3e:b0:81:91:e7:5b:35:fd:13:a7:41:9b:30:
90:f2:47:87:bd:4f:4e:19:67
$\endgroup$
  • 1
    $\begingroup$ An RSA public key needs to specify the public exponent; what would you use? Would you just assume a common value (say, 65537), and just be willing to have the certificate not work if the value that the key generated selected was anything else? $\endgroup$ – poncho Dec 4 '14 at 18:16
  • $\begingroup$ Probably would try to assume in this case that it's 3 or 65537. The problem is that I was only sent a public key in this hexadecimal format and I'm wondering if I'm the stupid one not being able to create a valid .pem from it. $\endgroup$ – madhenry Dec 5 '14 at 8:47
  • $\begingroup$ If you know how the key(pair) was generated, that may help. Java commandline keytool always uses the JCE default of 65537 (but a custom Java program might use something else). OpenSSL commandline genrsa supports only 3 and 65537 and defaults to the latter, but the newer and less-known genpkey is more flexible. Etc. Also to be clear: this maybe gives you the publickey, NOT a certificate. A cert requires much more. $\endgroup$ – dave_thompson_085 Dec 13 '14 at 13:17

Browse other questions tagged or ask your own question.