Generating a Parameter Set for the Diffie-Hellman Key Agreement Algorithm : Diffie Hellman « Security « Java Tutorial






import java.security.AlgorithmParameterGenerator;
import java.security.AlgorithmParameters;

import javax.crypto.spec.DHParameterSpec;

public class Main {
  public static void main(String[] argv) throws Exception {
    AlgorithmParameterGenerator paramGen = AlgorithmParameterGenerator.getInstance("DH");
    paramGen.init(1024);

    AlgorithmParameters params = paramGen.generateParameters();
    DHParameterSpec dhSpec = (DHParameterSpec) params.getParameterSpec(DHParameterSpec.class);

    System.out.println("" + dhSpec.getP() + "," + dhSpec.getG() + "," + dhSpec.getL());
  }
}








36.14.Diffie Hellman
36.14.1.Diffie-Hellman Key Agreement
36.14.2.Diffie-Hellman with Elliptic Curve
36.14.3.Implementing the Diffie-Hellman key exchange
36.14.4.Generating a Parameter Set for the Diffie-Hellman Key Agreement Algorithm