3

I have a kwm (WebMoney key) file. I use related Key Extractor to extract the RSA Key.

Extracted data has following XML structure:

<RSAKeyValue>
    <Modulus>modulus data</Modulus>
    <D>more data</D>
</RSAKeyValue> 

I need to export PrivateKey from this XML so I can use OpenSSL to sign data using that PrivateKey

I found a .Net solution which shows how to extract private key. But I failed to achieve this in python OpenSSL

How can I obtain PrivateKey data with python OpenSSL?

Note: I already use OpenSSL to load PrivateKey from a pfx file using OpenSSL.crypto.load_pkcs12(<pfx_file>).get_privatekey() But I fail to extract PrivateKey from above XML data.

Community
  • 1
  • 1
Mp0int
  • 18,172
  • 15
  • 83
  • 114
  • Please show us what you tried in python. It boils down to creating a private key from the modulus and the private exponent (`D`) for python openssl libraries. – Maarten Bodewes Feb 20 '14 at 13:37
  • @owlstead I am not much experianced with encryption. I had a look up methods and functions of `OpenSSL` but could not found anything useful. – Mp0int Feb 21 '14 at 13:37
  • 1
    Try using this function in pycrypto: http://pythonhosted.org//pycrypto/Crypto.PublicKey.RSA.RSAImplementation-class.html#construct – David K. Hess Feb 24 '14 at 13:58

1 Answers1

1

I don't think you can directly construct an OpenSSL.crypto.PKey instance from the information available to you. The format gives you the modulus and d of an RSA private key. These are the two numbers that make up an RSA private key. The information is complete but it is not in a format supported by pyOpenSSL.

pyOpenSSL can load an RSA private key from a PEM file. It cannot initialize one directly from the modulus and d values. (As an aside, this is because OpenSSL itself discourages applications from operating on the components of key objects.)

The relatively new cryptography project, a dependency of pyOpenSSL since pyOpenSSL 0.14, may help you out someday, though I don't think it supports RSA quite yet.

Jean-Paul Calderone
  • 47,755
  • 6
  • 94
  • 122