Take the 2-minute tour ×
Information Security Stack Exchange is a question and answer site for Information security professionals. It's 100% free, no registration required.

I want to know to to generate working RSA key pair, with correct syntax. Let's say i have already generated somehow my numbers for 512bit key, which are:

e = 00065537

d = 2a3ff2f501835d7d0f7ccad34265525b0c91f800fc252324e4bb5668392ba55a65d812d658b7065725c259a12115918dbdbbea6cead9225a91c3fcc6b43f1cb3

m = 4bb26cf2e1e1cdbbf78f89a60d5af5cf094a7216f9fe2d0e2288dc14e6005e0b6de46dc38f0e92b8b3281e9f1cf87257fb54bff579907e8a3c114133b74cb815

How I can generate from this a proper key pair? Is there a generator somehere to automate that? Best solution for me would be to generate that keypair in javascript that would work here https://www.pidder.com/pidcrypt/?page=demo_rsa-encryption with pidcrypt.

share|improve this question

1 Answer 1

A RSA key pair consist in the following:

  • The modulus n, a big integer which is equal to the product of two big prime integers, p and q.
  • The public exponent e.
  • The private exponent d. d is such that ed = 1 when taken modulo p-1, and also when taken modulo q-1.
  • The first factor p.
  • The second factor q.
  • The value dp = d mod p-1.
  • The value dq = d mod q-1.
  • The value q' = q-1 mod p.

The public key contains only n and e.

The private key contains all of the values specified above. Stricto sensu, only n and d are needed for a perfunctory RSA implementation, but the other values allow for faster operation, and also "masking" (protection against side-channel leaks), so the RSA standard defines that a private key contains all the values (see appendix A.1).

From the value you have, assuming that your "m" is really the RSA modulus, the other values can be recomputed, at some effort (less than one second worth of CPU, but more human time than I care to invest in it). From all these values, you could then encode standard-compliant RSA public and private keys; but this requires some knowledge of ASN.1. Finally, a 512-bit RSA key is weak; use at least 1024 bits, preferably more (2048 bits ought to be fine). Some RSA implementations will refuse to work with RSA keys shorter than 1024 bits.

Bottom-line: don't generate the key yourself; use OpenSSL. With the command-line tool:

openssl genrsa -out rsakey.pem 2048

will generate a 2048-bit RSA private key with all the proper encoding; then this:

openssl rsa -in rsakey.pem -pubout

will print out the public key, there again with the encoding done.

share|improve this answer
Yeah, what he said. –  u2702 Aug 13 '13 at 21:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.