[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 |