• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

Problem encrypting with openssl, decrypting with bouncy castle

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 220
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic