wood burning stoves*
The moose likes Security and the fly likes Problem encrypting with openssl, decrypting with bouncy castle Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » Security
Bookmark "Problem encrypting with openssl, decrypting with bouncy castle " Watch "Problem encrypting with openssl, decrypting with bouncy castle " New topic
Author

Problem encrypting with openssl, decrypting with bouncy castle

raul marzo
Greenhorn

Joined: Apr 09, 2007
Posts: 21
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.


<a href="http://benderscasino.blogspot.com/" target="_blank" rel="nofollow">http://benderscasino.blogspot.com/</a>
Nicholas Jordan
Ranch Hand

Joined: Sep 17, 2006
Posts: 1282
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.


"The differential equations that describe dynamic interactions of power generators are similar to that of the gravitational interplay among celestial bodies, which is chaotic in nature."
greg stark
Ranch Hand

Joined: Aug 10, 2006
Posts: 220
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.



Nice to meet you.
 
wood burning stoves
 
subject: Problem encrypting with openssl, decrypting with bouncy castle
 
Similar Threads
encryption decryption
Help to decrypt string containing RSA public key
need to generate RSA keys from txt files
signer information does not match? Help...
RSA encryption