protected KeyPair generateKeyPair(){
  KeyPair keyPair=null;
  DHParameterSpec keySpec=new DHParameterSpec(DH_MODULUS,DH_BASE);
  try {
    KeyPairGenerator keyGen=KeyPairGenerator.getInstance("DH");
    keyGen.initialize(keySpec);
    keyPair=keyGen.generateKeyPair();
    keyAgreement=KeyAgreement.getInstance("DH");
    keyAgreement.init(keyPair.getPrivate());
  }
 catch (  Exception e) {
    log.error("Error generating keypair",e);
  }
  return keyPair;
}

protected KeyPair generateKeyPair ( ) { KeyPair keyPair = null ; DHParameterSpec keySpec = new DHParameterSpec ( DH_MODULUS , DH_BASE ) ; try { KeyPairGenerator keyGen = KeyPairGenerator . getInstance ( "DH" ) ; keyGen . initialize ( keySpec ) ; keyPair = keyGen . generateKeyPair ( ) ; keyAgreement = KeyAgreement . getInstance ( "DH" ) ; keyAgreement . init ( keyPair . getPrivate ( ) ) ; } catch ( Exception e ) { log . error ( "Error generating keypair" , e ) ; } return keyPair ; }
creates a diffie - hellman key pair .
