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!

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
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
99 views