FileDocCategorySizeDatePackage
DHBasicAgreement.javaAPI DocAndroid 1.5 API2240Wed May 06 22:41:06 BST 2009org.bouncycastle.crypto.agreement

DHBasicAgreement

public class DHBasicAgreement extends Object implements org.bouncycastle.crypto.BasicAgreement
a Diffie-Hellman key agreement class.

note: This is only the basic algorithm, it doesn't take advantage of long term public keys if they are available. See the DHAgreement class for a "better" implementation.

Fields Summary
private org.bouncycastle.crypto.params.DHPrivateKeyParameters
key
private org.bouncycastle.crypto.params.DHParameters
dhParams
private SecureRandom
random
Constructors Summary
Methods Summary
public java.math.BigIntegercalculateAgreement(org.bouncycastle.crypto.CipherParameters pubKey)
given a short term public key from a given party calculate the next message in the agreement sequence.

        DHPublicKeyParameters   pub = (DHPublicKeyParameters)pubKey;

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

        return pub.getY().modPow(key.getX(), dhParams.getP());
    
public voidinit(org.bouncycastle.crypto.CipherParameters param)

        AsymmetricKeyParameter  kParam;

        if (param instanceof ParametersWithRandom)
        {
            ParametersWithRandom    rParam = (ParametersWithRandom)param;

            this.random = rParam.getRandom();
            kParam = (AsymmetricKeyParameter)rParam.getParameters();
        }
        else
        {
            this.random = new SecureRandom();
            kParam = (AsymmetricKeyParameter)param;
        }

        
        if (!(kParam instanceof DHPrivateKeyParameters))
        {
            throw new IllegalArgumentException("DHEngine expects DHPrivateKeyParameters");
        }

        this.key = (DHPrivateKeyParameters)kParam;
        this.dhParams = key.getParameters();