Date: Thu, 8 Jan 1998 12:34:02 -0800 (PST)
From: Jan Luehe <Jan.Luehe@Eng>
Subject: Re: Question on RSAPublicKeySpec
To: java-security@web1.javasoft.com, vgoenka@novell.com
Vishal:
> From what I understand out of the way KeySpec and KeyFactory is used, in
> order to create an RSAPublicKey from an encoded byte[] containing the key,
> one needs to do something like this :
>
> RSAPublicKeySpec keySpec = new RSAPublicKeySpec(keyData); // Assuming
> byte[] keyData;
> KeyFactory keyFactory = KeyFactory.getInstance("RSA");
> PublicKey rsaPubKey = keyFactory.generatePublic(keySpec);
>
> My question is that in the EarlyAccess of JCE, RSAPublicKeySpec doesn't have
> a constructor that takes a byte[] as argument. Nor does the class
> RSAPublicKey have any such constructor. Does it mean that I need to have
> another class to convert the byte[] keyData to an RSAKey (with modulus and
> exponent). If so, why would I use RSAPublicKeySpec at all ??
You would use "RSAPublicKeySpec" only in the case where you have all
the components of the RSA public key (i.e., the modulus and
the public exponent) available as separate items.
To generate an RSA public key from its encoding, you should use
"X509EncodedKeySpec":
import java.security.*;
import java.security.spec.*;
X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyData);
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
PublicKEy rsaPubKey = keyFactory.generatePublic(keySpec);
Jan