import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.PublicKey;
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("-- Public Key ----");
PublicKey pubKey = kp.getPublic();
System.out.println(" Algorithm=" + pubKey.getAlgorithm());
System.out.println(" Encoded=" + pubKey.getEncoded());
System.out.println(" Format=" + pubKey.getFormat());
}
}
|