views:

86

answers:

2

The title basically says it all.

I have a hexadecimal string representing a private key, and for me to be able to use it with OpenSSL, I need to be able to convert it to some format supported by OpenSSL, be it PEM or whatever.

I know that one can read a PEM formatted key and print it out in a format like this:

    Private-Key: (1024 bit)
modulus:
    01:02:03:04..
publicExponent: 65537 (0x10001)
privateExponent:
    01:02:03:04..
prime1:
    01:02:03:04..
prime2:
    01:02:03:04..
exponent1:
    01:02:03:04..
exponent2:
    01:02:03:04..
coefficient:
    01:02:03:04..

But I have been unable to find any information that converts a key from this format to the PEM format. Will I really be forced to RFC warrior this and write my own converter?

A: 

I haven't tried it this way, but you may want to look at the Bouncy Castle API, starting here:

http://www.bouncycastle.org/docs/docs1.6/index.html

It appears you can set the parts of the private key, and then you can use their API to save it to a standard format.

They have a Java and .NET API available.

James Black
A: 

Actually, I found a solution myself.

To do this, split the format I described above into a 8 strings of hexadecimal.

After that, the only thing you need to do is to read the keys from disk or whatever, then use the BN_hex2bn() function and fill the RSA struct. When you've filled it, you can use PEM_write_RSAPrivateKey to write it to disk.

I know the answer isn't very detailed, but if you man the functions(You being someone else that runs into this) it'll all be clear.

identity