Code example for DHPrivateKey

Methods: getParamsgetX

    if (! (incoming instanceof DHPublicKey))
      throw new InvalidKeyException("Key MUST be a DHPublicKey");
    DHPublicKey pub = (DHPublicKey) incoming;
    DHParameterSpec s1 = key.getParams();
    DHParameterSpec s2 = pub.getParams();
    if (! s1.getG().equals(s2.getG()) || ! s1.getP().equals(s2.getP()))
      throw new InvalidKeyException("Incompatible key");
    if (! lastPhase)
      throw new IllegalArgumentException(
          "This key-agreement MUST be concluded in one step only"); 
    BigInteger resultBI = pub.getY().modPow(key.getX(), s1.getP());
    result = resultBI.toByteArray();
    if (result[0] == 0x00)
        byte[] buf = new byte[result.length - 1];
        System.arraycopy(result, 1, buf, 0, buf.length);
        result = buf;
Stop searching for code, let great code find you!  Add Codota to your java IDE