这里面包含了一百多个JAVA源文件
源代码在线查看: e198. generating a public private key pair.txt
This example generates a key pair for various public/private key algorithms. See also e197 Listing All Available Public/Private Key Generators.
try {
// Generate a 1024-bit Digital Signature Algorithm (DSA) key pair
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA");
keyGen.initialize(1024);
KeyPair keypair = keyGen.genKeyPair();
PrivateKey privateKey = keypair.getPrivate();
PublicKey publicKey = keypair.getPublic();
// Generate a 576-bit DH key pair
keyGen = KeyPairGenerator.getInstance("DH");
keyGen.initialize(576);
keypair = keyGen.genKeyPair();
privateKey = keypair.getPrivate();
publicKey = keypair.getPublic();
// Generate a 1024-bit RSA key pair
keyGen = KeyPairGenerator.getInstance("RSA");
keyGen.initialize(1024);
keypair = keyGen.genKeyPair();
privateKey = keypair.getPrivate();
publicKey = keypair.getPublic();
} catch (java.security.NoSuchAlgorithmException e) {
}