The contents of this package hierarchy is organised as follows:
The four key-pair generation algorithms currently implemented in this library are:
gnu.crypto.key.dh
,gnu.crypto.key.dss
,gnu.crypto.key.rsa
,gnu.crypto.key.srp6
.The Key Agreement protocols currently implemented in this library are:
The following diagram shows the important classes participating in this package, for key-pair generation, with special emphasis on the DSS classes:
The next diagram shows the sequences involved in generating a keypair.
The following example shows the code that can be used to generate a key- pair:
import gnu.crypto.sig.rsa.RSA; import gnu.crypto.key.rsa.RSAKeyPairGenerator; import java.math.BigInteger; import java.security.KeyPair; import java.security.interfaces.RSAPrivateKey; import java.security.interfaces.RSAPrivateCrtKey; import java.security.interfaces.RSAPublicKey; import java.util.HashMap; import java.util.Random; ... RSAKeyPairGenerator kpg = new RSAKeyPairGenerator(); HashMap map = new HashMap(); map.put(RSAKeyPairGenerator.MODULUS_LENGTH, new Integer(1024)); kpg.setup(map); KeyPair kp = kpg.generate(); BigInteger n1 = ((RSAPublicKey) kp.getPublic()).getModulus(); BigInteger e = ((RSAPublicKey) kp.getPublic()).getPublicExponent(); BigInteger n2 = ((RSAPrivateKey) kp.getPrivate()).getModulus(); BigInteger d = ((RSAPrivateKey) kp.getPrivate()).getPrivateExponent(); BigInteger p = ((RSAPrivateCrtKey) kp.getPrivate()).getPrimeP(); BigInteger q = ((RSAPrivateCrtKey) kp.getPrivate()).getPrimeQ(); BigInteger dP = ((RSAPrivateCrtKey) kp.getPrivate()).getPrimeExponentP(); BigInteger dQ = ((RSAPrivateCrtKey) kp.getPrivate()).getPrimeExponentQ(); BigInteger qInv = ((RSAPrivateCrtKey) kp.getPrivate()).getCrtCoefficient();