1
package org.bouncycastle.crypto.generators;
3
import org.bouncycastle.crypto.AsymmetricCipherKeyPair;
4
import org.bouncycastle.crypto.AsymmetricCipherKeyPairGenerator;
5
import org.bouncycastle.crypto.KeyGenerationParameters;
6
import org.bouncycastle.crypto.params.DHKeyGenerationParameters;
7
import org.bouncycastle.crypto.params.DHParameters;
8
import org.bouncycastle.crypto.params.DHPrivateKeyParameters;
9
import org.bouncycastle.crypto.params.DHPublicKeyParameters;
11
import java.math.BigInteger;
14
* a basic Diffie-Hellman key pair generator.
16
* This generates keys consistent for use with the basic algorithm for
19
public class DHBasicKeyPairGenerator
20
implements AsymmetricCipherKeyPairGenerator
22
private DHKeyGenerationParameters param;
25
KeyGenerationParameters param)
27
this.param = (DHKeyGenerationParameters)param;
30
public AsymmetricCipherKeyPair generateKeyPair()
32
DHKeyGeneratorHelper helper = DHKeyGeneratorHelper.INSTANCE;
33
DHParameters dhp = param.getParameters();
35
BigInteger x = helper.calculatePrivate(dhp, param.getRandom());
36
BigInteger y = helper.calculatePublic(dhp, x);
38
return new AsymmetricCipherKeyPair(
39
new DHPublicKeyParameters(y, dhp),
40
new DHPrivateKeyParameters(x, dhp));