4

I have calculated n, e, d, p, q values of an RSA key. Now, how can I generate a private key file (pem or der) with openssl command line tools?

I was thinking about

openssl asn1parse -genconf asn1.cnf -noout -out asn1.der

but I cannot understand how to build the conf file.

Lorenzo Barbagli
  • 1,241
  • 2
  • 16
  • 34
  • 1
    Stack Overflow is a site for programming and development questions. This question appears to be off-topic because it is not about programming or development. See [What topics can I ask about here](http://stackoverflow.com/help/on-topic) in the Help Center. Perhaps [Super User](http://superuser.com/) or [Unix & Linux Stack Exchange](http://unix.stackexchange.com/) would be a better place to ask. Also see [Where do I post questions about Dev Ops?](http://meta.stackexchange.com/q/134306). – jww Jan 21 '16 at 06:20

1 Answers1

11

The OpenSSL manpage for asn_generate_nconf comes with an example cnf for generating the private_key ASN.1 sequence that should work with your cmdline:

asn1=SEQUENCE:private_key
[private_key]
version=INTEGER:0

n=INTEGER:0xBB6FE79432CC6EA2D8F970675A5A87BFBE1AFF0BE63E879F2AFFB93644\
D4D2C6D000430DEC66ABF47829E74B8C5108623A1C0EE8BE217B3AD8D36D5EB4FCA1D9

e=INTEGER:0x010001

d=INTEGER:0x6F05EAD2F27FFAEC84BEC360C4B928FD5F3A9865D0FCAAD291E2A52F4A\
F810DC6373278C006A0ABBA27DC8C63BF97F7E666E27C5284D7D3B1FFFE16B7A87B51D

p=INTEGER:0xF3929B9435608F8A22C208D86795271D54EBDFB09DDEF539AB083DA912\
D4BD57

q=INTEGER:0xC50016F89DFF2561347ED1186A46E150E28BF2D0F539A1594BBD7FE467\
46EC4F

exp1=INTEGER:0x9E7D4326C924AFC1DEA40B45650134966D6F9DFA3A7F9D698CD4ABEA\
9C0A39B9

exp2=INTEGER:0xBA84003BB95355AFB7C50DF140C60513D0BA51D637272E355E397779\
E7B2458F

coeff=INTEGER:0x30B9E4F2AFA5AC679F920FC83F1F2DF1BAF1779CF989447FABC2F5\
628657053A

As an alternative rsatool.py can generate the base64 encoded ASN.1 privkey.pem or plain asn.1 der sequence with a simple cmdline

#>python rsatool.py -n <n> -p <p> -q <q> -e <e> -v PEM -o privkey.pem

or for output in ASN.1 der:

#>python rsatool.py -n <n> -p <p> -q <q> -e <e> -v DER -o privkey.key
zrneely
  • 1,802
  • 3
  • 17
  • 26
tintin
  • 3,176
  • 31
  • 34
  • The question is specific; it says Bash. Perhaps you should answer the question at hand before moving on to questions that were not asked. But don't worry about it too much. The question appears to be off-topic since it has nothing to do with programming or development. – jww Jan 21 '16 at 06:22