![JAR search and dependency download from the Maven repository](/logo.png)
org.spongycastle.crypto.params.DHPublicKeyParameters Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of core Show documentation
Show all versions of core Show documentation
Spongy Castle is a package-rename (org.bouncycastle.* to org.spongycastle.*) of Bouncy Castle
intended for the Android platform. Android unfortunately ships with a stripped-down version of
Bouncy Castle, which prevents easy upgrades - Spongy Castle overcomes this and provides a full,
up-to-date version of the Bouncy Castle cryptographic libs.
The newest version!
package org.spongycastle.crypto.params;
import java.math.BigInteger;
public class DHPublicKeyParameters
extends DHKeyParameters
{
private static final BigInteger ONE = BigInteger.valueOf(1);
private static final BigInteger TWO = BigInteger.valueOf(2);
private BigInteger y;
public DHPublicKeyParameters(
BigInteger y,
DHParameters params)
{
super(false, params);
this.y = validate(y, params);
}
private BigInteger validate(BigInteger y, DHParameters dhParams)
{
if (y == null)
{
throw new NullPointerException("y value cannot be null");
}
// TLS check
if (y.compareTo(TWO) < 0 || y.compareTo(dhParams.getP().subtract(TWO)) > 0)
{
throw new IllegalArgumentException("invalid DH public key");
}
if (dhParams.getQ() != null)
{
if (ONE.equals(y.modPow(dhParams.getQ(), dhParams.getP())))
{
return y;
}
throw new IllegalArgumentException("Y value does not appear to be in correct group");
}
else
{
return y; // we can't validate without Q.
}
}
public BigInteger getY()
{
return y;
}
public int hashCode()
{
return y.hashCode() ^ super.hashCode();
}
public boolean equals(
Object obj)
{
if (!(obj instanceof DHPublicKeyParameters))
{
return false;
}
DHPublicKeyParameters other = (DHPublicKeyParameters)obj;
return other.getY().equals(y) && super.equals(obj);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy