KeyPair Generator For Public Key : Key Generator « Security « Java






KeyPair Generator For Public Key

   
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());
  }
}

           
         
    
    
  








KeyPairGeneratorForPublicKey.zip( 1,198 k)

Related examples in the same category

1.Using the KeyGenerator class and showing how to create a SecretKeySpec from an encoded key
2.Key Generator Mac
3.Generate DSA key pair
4.KeyPair Generator For Private Key
5.Wrap And Unwrap Key
6.Generating a Public/Private Key Pair
7.Generate a 576-bit DH key pair
8.Generate a 1024-bit RSA key pair
9.Getting the Bytes of a Generated Key Pair
10.Get the bytes of the public and private keys
11.The bytes can be converted back to public and private key objects
12.Generate a key for the HMAC-SHA1 keyed-hashing algorithm
13.Asymmetric Key Maker
14.Generating a Symmetric Key
15.Xml dap Certs And Keys
16.Diffie-Hellman key exchange