2

Any idea how I can access key from a keystore or keyfile ( basically PKCS12 type). I do not want to create any connection. I just want to access this private key that will be on users machine, encrypt it and then send it as plain text string to the server as a param. We are doing this for some kind of authentication.

So how can I simply extract the key from keyfile? No SSL connection/certificate/etc needed.

I am using python to implement this.

SOL:

I was able to extract key using pyOpenSSL using below code:

>>> p12 = load_pkcs12(file("C:\XYZ\DistProfile.p12", "rb").read(), "passwd")  
>>> p12.get_certificate()
>>> p12.get_privatekey()
>>> key_pem = dump_privatekey(FILETYPE_PEM,p12.get_privatekey())
Key_pem will have the private key 
ssal
  • 281
  • 4
  • 14
  • 2
    related: [Python: reading a pkcs12 certificate with pyOpenSSL](http://stackoverflow.com/questions/6345786/python-reading-a-pkcs12-certificate-with-pyopenssl-crypto). If you [convert pkcs12 to pem format](http://stackoverflow.com/q/9497719/4279) then you could also use `M2Crypto` instead of `pyOpenSSL` to manipulate the private key. – jfs Mar 26 '13 at 08:35
  • Thanks, I am currently trying with pyOpenSSL. I am trying to use load_pkcs12. and I am not completely aware of concepts. I was not sure what is the right way. I wanted to use M2Crypto but I am working windows desktop application and thought pyOpenSSL will be easier to use on windows as compared to M2Crypto. Can I not use pyOpenSSL to manipulate the key? – ssal Mar 26 '13 at 09:20
  • both Python libraries wrap the same C library (OpenSSL) but capabilities are different. What library to choose depends on what specifically you are trying to do. M2Crypto should work on Windows ([there is Windows installer](http://chandlerproject.org/Projects/MeTooCrypto#Downloads)). [Update your question](http://stackoverflow.com/posts/15631824/edit) to include the code that you use to extract the key and corresponding errors or [ask a new question](http://stackoverflow.com/questions/ask). – jfs Mar 26 '13 at 14:13

0 Answers0