RSA encryption in standard JCE provider
843810Dec 24 2002 — edited Jan 2 2003I 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