Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

RSA encryption in standard JCE provider

843810Dec 24 2002 — edited Jan 2 2003
I am trying to use RSA for a session key exchange between two parties. In the JDK (1.4.1) API it seems that KeyPairGenerator can only take "DiffieHellman" as argument to generate a pair of keys. This seems to work just fine. I don't know if these keys should be used or not in a RSA encryption, but it seems there's no other way to generate a pair of keys. On the other hand, what is the string used to initialize the cipher used for encryption (i.e., transformation)? "RSA" doesn't work even though it is specified in the API docs. Here's a piece of code to show you what I am attempting to do:

....

KeyPairGenerator kpg = KeyPairGenerator.getInstance("DiffieHellman");
KeyPair kp = kpg.generateKeyPair();
PrivateKey prvk = kp.getPrivate();
PublicKey pubk = kp.getPublic();

Cipher c = Cipher.getInstance("RSA");
c.init(Cipher.ENCRYPT_MODE, pubk);
.....

Thanks,
Radu

Comments

843810
You can use "RSA" to generate a pair of keys, i have done it.
And I could also sign messages with "SHA1withRSA".
But to use a cipher you need an implementation because Sun does not provide one.
You can use the one in http://www.bouncycastle.org/.
The problem is that you cannot cipher long messages.
See ya!
1 - 1
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Jan 30 2003
Added on Dec 24 2002
1 comment
86 views