import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.PrivateKey;
import java.security.SecureRandom;
import java.security.Security;
public class MainClass {
public KeyPair generateKeyPair(long seed)throws Exception {
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
KeyPairGenerator keyGenerator = KeyPairGenerator.getInstance("DSA");
SecureRandom rng = SecureRandom.getInstance("SHA1PRNG", "SUN");
rng.setSeed(seed);
keyGenerator.initialize(1024, rng);
return (keyGenerator.generateKeyPair());
}
public static void main(String args[]) throws Exception {
MainClass kpge = new MainClass();
KeyPair kp = kpge.generateKeyPair(999);
System.out.println("\n-- Private Key ----");
PrivateKey priKey = kp.getPrivate();
System.out.println(" Algorithm=" + priKey.getAlgorithm());
System.out.println(" Encoded=" + priKey.getEncoded());
System.out.println(" Format=" + priKey.getFormat());
}
}
|