• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

asymmetric ecryption / decryption

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there !
I'm sorry I have to occupy your attention, again.
But I didn't find any propper example anywhere.
Here's my problem:
I've got a private and a public key (RSA 1024)
and I want to encrypt a String with the public key
and decrypt it with the private key.
Do you maybe have a code snipped which shows me howto?
I would be very happy to hear from you ...
Thanx, Thomas.
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is not normally done, as asymmetric encryption is very slow. The usual procedure is to generate a random (symmetric) session key, encrypt this using RSA or whatever you're using, and then encrypt the actual String with the session key.
One of the reasons that you can't find any examples is probably that the Sun JCE provider doesn't support any asymmetric encryption algorithms; all it has is Diffie-Hellman key exchange (and the JCE documentation does have an example of that). To get RSA support you need a third-party JCE provider such as Cryptix.
Once installed, writing code to use asymmetric encryption is not all that different from symmetric encryption. There are plenty of examples of the latter both in the JCE documentation and places like the Java Almanac.
- Peter
[ November 10, 2003: Message edited by: Peter den Haan ]
 
Author
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As Peter mentioned, you will need a JCE Provider that supports asymmetric encryption -- something that Sun doesn't include in J2SE SDK. However, the BouncyCastle JCE includes one.
I have a sample program using BouncyCastle in my book. Thesource file is available online. Look for class AsymmetricCipherTest.
 
She's out of the country right now, toppling an unauthorized dictatorship. Please leave a message with this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic