code: 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);
      }
docs: 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.