    public BigInteger calculateAgreement(
        CipherParameters   pubKey)
    {
        DHPublicKeyParameters   pub = (DHPublicKeyParameters)pubKey;

        if (!pub.getParameters().equals(dhParams))
        {
            throw new IllegalArgumentException("Diffie-Hellman public key has wrong parameters.");
        }

        BigInteger result = pub.getY().modPow(key.getX(), dhParams.getP());
        if (result.compareTo(ONE) == 0)
        {
            throw new IllegalStateException("Shared key can't be 1");
        }

        return result;
    }
Weaknesses in this category are related to errors in the management of cryptographic keys.