private static void validateDHPublicKey(DHPublicKey publicKey) throws InvalidKeyException {
  DHParameterSpec paramSpec=publicKey.getParams();
  BigInteger p=paramSpec.getP();
  BigInteger g=paramSpec.getG();
  BigInteger y=publicKey.getY();
  validateDHPublicKey(p,g,y);
}

private static void validateDHPublicKey ( DHPublicKey publicKey ) throws InvalidKeyException { DHParameterSpec paramSpec = publicKey . getParams ( ) ; BigInteger p = paramSpec . getP ( ) ; BigInteger g = paramSpec . getG ( ) ; BigInteger y = publicKey . getY ( ) ; validateDHPublicKey ( p , g , y ) ; }
returns whether the diffie - hellman public key is valid or not . per rfc 2631 and nist sp800 - 56a , the following algorithm is used to validate diffie - hellman public keys : 1 . verify that y lies within the interval [ 2 , p - 1 ] . if it does not , the key is invalid . 2 . compute y ^ q mod p . if the result = = 1 , the key is valid . otherwise the key is invalid .
