Generate .pem RSA public key file using base 10 modulus and exponent?

1

1

My question is as simple as the title: given the modulus and exponent in base 10 of a public RSA key, how can I generate a .pem file? (I'm using Unix). Thanks.

My apologizes if this is the wrong forum for this question, or a poor question altogether; I've tried extensive googling to no luck, and I have zero experience with RSA.

nanogru

Posted 2017-04-17T22:43:54.353

Reputation: 111

Answers

2

If you create a ASN1-formatted text file containing the modulus and exponent (plus a few other bits) then you can make a PEM file like this:

$ openssl asn1parse -genconf key.cnf -out key.der
$ openssl rsa -in key.der -inform der -out private.pem
$ openssl rsa -in key.der -inform der -out public.pem -pubout

where key.cnf contains the ASN1 data and looks something like this:

asn1=SEQUENCE:rsa_key

[rsa_key]
version=INTEGER:0
modulus=INTEGER:13671936028836425653
pubExp=INTEGER:65537
privExp=INTEGER:531444176792982513
p=INTEGER:3273361529
q=INTEGER:4176726557
e1=INTEGER:1295519345
e2=INTEGER:20202669
coeff=INTEGER:1526950891

This is taken from this article, pages 82-87 which explains how RSA works and creates a PEM file as part of that explanation. The above example is described on page 86.

The above includes the private exponent but should give you a pointer towards doing what you want. You may find man asn1parse helpful.

starfry

Posted 2017-04-17T22:43:54.353

Reputation: 1 169