Thread: [Jsdsi-users] < How to generate different Keypairs correctly? >
Status: Pre-Alpha
Brought to you by:
sajma
From: Feng-Shuo <fc...@an...> - 2004-05-02 05:16:56
|
Dear Sameer, Sean, and jsdsi experts, I read the mail list in archive about "Sun KeyPairGeneratory" but I = still don't really know how to generate different Keypairs through jsdsi = API. Following are some of ways I tried but neither one of them works well, = could you tell me what is the correct way to generate? 1. java.math.BigInteger s_m =3D new java.math.BigInteger("1024"); java.math.BigInteger s_e =3D new java.math.BigInteger("9"); jsdsi.RSAPublicKey s_rsapk =3D new jsdsi.RSAPublicKey(s_m, s_e, = "RSA"); KeyPair s_pair =3D s_rsapk.create(); PrivateKey s_priv =3D s_pair.getPrivate(); jsdsi.PublicKey s_pub =3D (jsdsi.PublicKey) s_pair.getPublic(); =20 ---> This method always generate the same Keypair 2. KeyPairGenerator keyGen =3D KeyPairGenerator.getInstance("RSA"); RSAKeyGenParameterSpec rsagen =3D new = RSAKeyGenParameterSpec(1024,RSAKeyGenParameterSpec.F0); keyGen.initialize(rsagen); KeyPair s_test_pair =3D keyGen.generateKeyPair(); PrivateKey s_priv =3D s_test_pair.getPrivate(); //-->Class Cast Error: jsdsi.PublicKey s_pub =3D (jsdsi.PublicKey) = s_test_pair.getPublic(); java.security.interfaces.RSAPublicKey pub =3D = (java.security.interfaces.RSAPublicKey)s_test_pair.getPublic(); jsdsi.RSAPublicKey s_pub =3D new jsdsi.RSAPublicKey(pub); =20 ---> Throw Class Cast Error when pass KeyPair into "create" method in = "signature" class (I think error is occured in " assert(kp.getPublic() instanceof = Principal) within signature class ") =20 3. KeyPairGenerator keyGen =3D KeyPairGenerator.getInstance("RSA"); RSAKeyGenParameterSpec rsagen =3D new = RSAKeyGenParameterSpec(1024,RSAKeyGenParameterSpec.F0); keyGen.initialize(rsagen); KeyPair s_test_pair =3D keyGen.generateKeyPair(); PrivateKey s_priv =3D s_test_pair.getPrivate(); java.security.interfaces.RSAPublicKey pub =3D = (java.security.interfaces.RSAPublicKey)s_test_pair.getPublic(); jsdsi.RSAPublicKey s_pub =3D new jsdsi.RSAPublicKey(pub); /* Create another keypair from jsdsi.RSAPublicKey.create() */ KeyPair s_pair =3D s_pub.create(); =20 ---> This method always generate the same Keypair Regards, Matt |
From: Sean R. <sra...@ae...> - 2004-05-02 15:59:33
|
Hi, I would say that the best way is to use jsdsi.util.KeyPairFactory And, as the javadoc for that class mentions: Note: Care should be taken when creating Keys without specifying a keysize, SecureRandom, or any AlgorithmParameterSpec, as it has been noted that without, keys are predictable when using some Providers. But in your examples you are always creating 1024 bit keys, so that is no problem. Regards, Sean On Sun, 2004-05-02 at 06:16, Feng-Shuo wrote: > > Dear Sameer, Sean, and jsdsi experts, > I read the mail list in archive about "Sun KeyPairGeneratory" but > I still don't really know how to generate different Keypairs through > jsdsi API. > > Following are some of ways I tried but neither one of them works well, > could you tell me what is the correct way to generate? > 1. java.math.BigInteger s_m = new java.math.BigInteger("1024"); > java.math.BigInteger s_e = new java.math.BigInteger("9"); > jsdsi.RSAPublicKey s_rsapk = new jsdsi.RSAPublicKey(s_m, s_e, > "RSA"); > > KeyPair s_pair = s_rsapk.create(); > PrivateKey s_priv = s_pair.getPrivate(); > jsdsi.PublicKey s_pub = (jsdsi.PublicKey) s_pair.getPublic(); > > ---> This method always generate the same Keypair > > 2. KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA"); > RSAKeyGenParameterSpec rsagen = new > RSAKeyGenParameterSpec(1024,RSAKeyGenParameterSpec.F0); > keyGen.initialize(rsagen); > > KeyPair s_test_pair = keyGen.generateKeyPair(); > PrivateKey s_priv = s_test_pair.getPrivate(); > > //-->Class Cast Error: jsdsi.PublicKey s_pub = (jsdsi.PublicKey) > s_test_pair.getPublic(); > java.security.interfaces.RSAPublicKey pub = > (java.security.interfaces.RSAPublicKey)s_test_pair.getPublic(); > jsdsi.RSAPublicKey s_pub = new jsdsi.RSAPublicKey(pub); > > ---> Throw Class Cast Error when pass KeyPair into "create" method in > "signature" class > (I think error is occured in " assert(kp.getPublic() instanceof > Principal) within signature class ") > > 3. KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA"); > RSAKeyGenParameterSpec rsagen = new > RSAKeyGenParameterSpec(1024,RSAKeyGenParameterSpec.F0); > keyGen.initialize(rsagen); > > KeyPair s_test_pair = keyGen.generateKeyPair(); > PrivateKey s_priv = s_test_pair.getPrivate(); > > java.security.interfaces.RSAPublicKey pub = > (java.security.interfaces.RSAPublicKey)s_test_pair.getPublic(); > jsdsi.RSAPublicKey s_pub = new jsdsi.RSAPublicKey(pub); > /* Create another keypair from jsdsi.RSAPublicKey.create() */ > KeyPair s_pair = s_pub.create(); > > ---> This method always generate the same Keypair > > Regards, > > Matt -- Dr. Sean Radford, MBBS, MSc sra...@ae... http://www.aegeus-technology.com |