Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem encrypting with openssl, decrypting with bouncy castle

 
raul marzo
Greenhorn
Posts: 21
  • 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
  • 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
  • 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.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic