RSA encrypt session key  
Author Message
P.G.Tomlinson





PostPosted: 2005-3-10 23:15:00 Top

java-programmer, RSA encrypt session key Does anyone know how to encrypt a secret key with a public key algorithm
to transmit it to another computer securely. Have tried using RSA and
have had no look in the following code:

public byte[] encryptSessionKey(SecretKey sKey, PrivateKey pKey, String
algorithm)
{
System.out.println("linex");
Cipher cipher = Cipher.getInstance(algorithm+"/ECB/PKCS#1");
System.out.println("liney");
cipher.init(Cipher.WRAP_MODE, pKey);
System.out.println("linez");
return cipher.wrap(sKey);
}

It prints out liney but not linez which suggests the Cipher object can
not encrypt a session key in wrap mode.

Thanks.
 
Karl Scheibelhofer





PostPosted: 2005-3-12 0:01:00 Top

java-programmer >> RSA encrypt session key your pKey should be a public key. wrapping -> public key; unwrapping ->
private key.

the correct algorithm name should be "RSA/ECB/PKCS1Padding". if the RSA
implementation supports key wrapping depends on the JCE provider which you
use.

Karl

Karl Scheibelhofer, IAIK - Graz University of Technology
Inffeldgasse 16a, 8010 Graz, Austria
Fax: +43 316 873 5520
http://jce.iaik.tugraz.at/
Visit us at the RSA conference in San Francisco, 14-18 Feb 2005, booth 438


"P.G.Tomlinson" <email***@***.com> wrote in message
news:d0poae$ncq$email***@***.com...
> Does anyone know how to encrypt a secret key with a public key algorithm
> to transmit it to another computer securely. Have tried using RSA and
> have had no look in the following code:
>
> public byte[] encryptSessionKey(SecretKey sKey, PrivateKey pKey, String
> algorithm)
> {
> System.out.println("linex");
> Cipher cipher = Cipher.getInstance(algorithm+"/ECB/PKCS#1");
> System.out.println("liney");
> cipher.init(Cipher.WRAP_MODE, pKey);
> System.out.println("linez");
> return cipher.wrap(sKey);
> }
>
> It prints out liney but not linez which suggests the Cipher object can
> not encrypt a session key in wrap mode.
>
> Thanks.


 
P.G.Tomlinson





PostPosted: 2005-3-14 17:07:00 Top

java-programmer >> RSA encrypt session key Thanks a lot Karl. Will try that.

P.G.Tomlinson wrote:
> Does anyone know how to encrypt a secret key with a public key algorithm
> to transmit it to another computer securely. Have tried using RSA and
> have had no look in the following code:
>
> public byte[] encryptSessionKey(SecretKey sKey, PrivateKey pKey, String
> algorithm)
> {
> System.out.println("linex");
> Cipher cipher = Cipher.getInstance(algorithm+"/ECB/PKCS#1");
> System.out.println("liney");
> cipher.init(Cipher.WRAP_MODE, pKey);
> System.out.println("linez");
> return cipher.wrap(sKey);
> }
>
> It prints out liney but not linez which suggests the Cipher object can
> not encrypt a session key in wrap mode.
>
> Thanks.