This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem encrypting with openssl, decrypting with bouncy castle

 
raul marzo
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.

I'm trying to extract the certificate and "rsa private key" from a pem file created with openssl, in a midlet application(J2ME). I've been able to extract the cert info using Bouncy castle ASN1 class, but I cannot get the private key data. I have the following code to extract the rsa private key and decrypt it, however, it throws an exception when I init the cipher.





The private key in the pem file I want to decrypt is something like this:

-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: DES-EDE3-CBC,F83023B53795F517

MwdlPLqo...
-----END RSA PRIVATE KEY-----


Could anybody told me what's wrong with the code, or tell me any alternative?
If I encrypt the private key with other algorithm, like AES, would be easier to decrypt the private key?

Thanks in advance.
 
Nicholas Jordan
Ranch Hand
Posts: 1282
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where's the stack trace ?

Also, I would shy the mind of any thought of seeking easier while doing crypto. I like to think of Cryptix as being Crypt Ticks ...tick.tock...tick.tock... a Hollywood character waiting for you to screw down the the lid on your own coffin.
 
greg stark
Ranch Hand
Posts: 220
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use the org.bouncycastle.openssl.PEMReader class. The result will have exactly one object, which you can read in and cast to KeyPair, e.g.

 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic