1

So I have to generate a private key (RSA) given its bit length, the modulus, the first prime and the public exponent.

The problem is that I have the modulus and prime1 in hexadecimal pairs. I've tried doing it manually but the number gets really long (obviously). I've also tried to use the openssl genpkey but for RSA it doesn't have the parameters I'd need.

Does someone know any way to do it or I will have to operate manually in hex/binary?

3
  • You're going to have to write a program to do it. The openssl command line tools are not going to do this for you. Jun 6, 2015 at 14:34
  • @GregS - I think its easier than that (I read it like you first time). He has the modulus n and p. He only needs to solve for q. With p, q and e, he can efficiently compute d. And then use the CRT to recover the other RSA private key parameters, like dp, dq and q-inv. Finally, he can stuff it in a RSA*. Viola!
    – jww
    Jun 6, 2015 at 23:00
  • @jww yeah, but I 3 pairs of hex values of the p where missing, so I had to "guess" them. I already solved it, but thanks for the time anyway!
    – lpares12
    Jun 7, 2015 at 17:09

1 Answer 1

-1

As James K Polk comments on the question, openssl doesn't support generating keys in this manner. You'll have to write a program yourself to do this.

For example, the following Java code would work. You'll need to handle the exceptions as well.

BigInteger modulus = /* modulus here */;
BigInteger exponent = /* exponent here */;
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
keyFactory.generatePrivate(new RSAPrivateKeySpec(modulus, exponent));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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