Methods Summary |
---|
private byte[] | bigIntToBytes(java.math.BigInteger r)
byte[] tmp = r.toByteArray();
if (tmp[0] == 0)
{
byte[] ntmp = new byte[tmp.length - 1];
System.arraycopy(tmp, 1, ntmp, 0, ntmp.length);
return ntmp;
}
return tmp;
|
protected java.security.Key | engineDoPhase(java.security.Key key, boolean lastPhase)
if (x == null)
{
throw new IllegalStateException("Diffie-Hellman not initialised.");
}
if (!(key instanceof DHPublicKey))
{
throw new InvalidKeyException("DHKeyAgreement doPhase requires DHPublicKey");
}
DHPublicKey pubKey = (DHPublicKey)key;
if (!pubKey.getParams().getG().equals(g) || !pubKey.getParams().getP().equals(p))
{
throw new InvalidKeyException("DHPublicKey not for this KeyAgreement!");
}
if (lastPhase)
{
result = ((DHPublicKey)key).getY().modPow(x, p);
return null;
}
else
{
result = ((DHPublicKey)key).getY().modPow(x, p);
}
return new JCEDHPublicKey(result, pubKey.getParams());
|
protected byte[] | engineGenerateSecret()
if (x == null)
{
throw new IllegalStateException("Diffie-Hellman not initialised.");
}
return bigIntToBytes(result);
|
protected int | engineGenerateSecret(byte[] sharedSecret, int offset)
if (x == null)
{
throw new IllegalStateException("Diffie-Hellman not initialised.");
}
byte[] secret = bigIntToBytes(result);
if (sharedSecret.length - offset < secret.length)
{
throw new ShortBufferException("DHKeyAgreement - buffer too short");
}
System.arraycopy(secret, 0, sharedSecret, offset, secret.length);
return secret.length;
|
protected javax.crypto.SecretKey | engineGenerateSecret(java.lang.String algorithm)
if (x == null)
{
throw new IllegalStateException("Diffie-Hellman not initialised.");
}
return new SecretKeySpec(bigIntToBytes(result), algorithm);
|
protected void | engineInit(java.security.Key key, java.security.spec.AlgorithmParameterSpec params, java.security.SecureRandom random)
if (!(key instanceof DHPrivateKey))
{
throw new InvalidKeyException("DHKeyAgreement requires DHPrivateKey for initialisation");
}
DHPrivateKey privKey = (DHPrivateKey)key;
this.random = random;
if (params != null)
{
if (!(params instanceof DHParameterSpec))
{
throw new InvalidAlgorithmParameterException("DHKeyAgreement only accepts DHParameterSpec");
}
DHParameterSpec p = (DHParameterSpec)params;
this.p = p.getP();
this.g = p.getG();
}
else
{
this.p = privKey.getParams().getP();
this.g = privKey.getParams().getG();
}
this.x = this.result = privKey.getX();
|
protected void | engineInit(java.security.Key key, java.security.SecureRandom random)
if (!(key instanceof DHPrivateKey))
{
throw new InvalidKeyException("DHKeyAgreement requires DHPrivateKey");
}
DHPrivateKey privKey = (DHPrivateKey)key;
this.random = random;
this.p = privKey.getParams().getP();
this.g = privKey.getParams().getG();
this.x = this.result = privKey.getX();
|