本文整理汇总了Java中org.bouncycastle.crypto.generators.DHBasicKeyPairGenerator.generateKeyPair方法的典型用法代码示例。如果您正苦于以下问题:Java DHBasicKeyPairGenerator.generateKeyPair方法的具体用法?Java DHBasicKeyPairGenerator.generateKeyPair怎么用?Java DHBasicKeyPairGenerator.generateKeyPair使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.crypto.generators.DHBasicKeyPairGenerator
的用法示例。
在下文中一共展示了DHBasicKeyPairGenerator.generateKeyPair方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateClientKeyExchange
import org.bouncycastle.crypto.generators.DHBasicKeyPairGenerator; //导入方法依赖的package包/类
public byte[] generateClientKeyExchange() throws IOException
{
// TODO RFC 2246 7.4.72
/*
* If the client certificate already contains a suitable Diffie-Hellman key, then
* Yc is implicit and does not need to be sent again. In this case, the Client Key
* Exchange message will be sent, but will be empty.
*/
// return new byte[0];
/*
* Generate a keypair (using parameters from server key) and send the public value
* to the server.
*/
DHBasicKeyPairGenerator dhGen = new DHBasicKeyPairGenerator();
dhGen.init(new DHKeyGenerationParameters(handler.getRandom(),
dhAgreeServerPublicKey.getParameters()));
this.dhAgreeClientKeyPair = dhGen.generateKeyPair();
BigInteger Yc = ((DHPublicKeyParameters)dhAgreeClientKeyPair.getPublic()).getY();
return BigIntegers.asUnsignedByteArray(Yc);
}
示例2: generateDHKeyPair
import org.bouncycastle.crypto.generators.DHBasicKeyPairGenerator; //导入方法依赖的package包/类
public static AsymmetricCipherKeyPair generateDHKeyPair(SecureRandom random,
DHParameters dhParams)
{
DHBasicKeyPairGenerator dhGen = new DHBasicKeyPairGenerator();
dhGen.init(new DHKeyGenerationParameters(random, dhParams));
return dhGen.generateKeyPair();
}
示例3: testSimpleWithRandom
import org.bouncycastle.crypto.generators.DHBasicKeyPairGenerator; //导入方法依赖的package包/类
private void testSimpleWithRandom(
DHBasicKeyPairGenerator kpGen)
{
//
// generate first pair
//
AsymmetricCipherKeyPair pair = kpGen.generateKeyPair();
DHPublicKeyParameters pu1 = (DHPublicKeyParameters)pair.getPublic();
DHPrivateKeyParameters pv1 = (DHPrivateKeyParameters)pair.getPrivate();
//
// generate second pair
//
pair = kpGen.generateKeyPair();
DHPublicKeyParameters pu2 = (DHPublicKeyParameters)pair.getPublic();
DHPrivateKeyParameters pv2 = (DHPrivateKeyParameters)pair.getPrivate();
//
// two way
//
DHBasicAgreement e1 = new DHBasicAgreement();
DHBasicAgreement e2 = new DHBasicAgreement();
e1.init(new ParametersWithRandom(pv1, new SecureRandom()));
e2.init(new ParametersWithRandom(pv2, new SecureRandom()));
BigInteger k1 = e1.calculateAgreement(pu2);
BigInteger k2 = e2.calculateAgreement(pu1);
if (!k1.equals(k2))
{
fail("basic with random 2-way test failed");
}
}
示例4: generateDHKeyPair
import org.bouncycastle.crypto.generators.DHBasicKeyPairGenerator; //导入方法依赖的package包/类
public static AsymmetricCipherKeyPair generateDHKeyPair(SecureRandom random, DHParameters dhParams)
{
DHBasicKeyPairGenerator dhGen = new DHBasicKeyPairGenerator();
dhGen.init(new DHKeyGenerationParameters(random, dhParams));
return dhGen.generateKeyPair();
}
示例5: testDHBasic
import org.bouncycastle.crypto.generators.DHBasicKeyPairGenerator; //导入方法依赖的package包/类
private void testDHBasic(
int size,
int privateValueSize,
BigInteger g,
BigInteger p)
{
DHBasicKeyPairGenerator kpGen = getDHBasicKeyPairGenerator(g, p, privateValueSize);
//
// generate first pair
//
AsymmetricCipherKeyPair pair = kpGen.generateKeyPair();
DHPublicKeyParameters pu1 = (DHPublicKeyParameters)pair.getPublic();
DHPrivateKeyParameters pv1 = (DHPrivateKeyParameters)pair.getPrivate();
checkKeySize(privateValueSize, pv1);
//
// generate second pair
//
pair = kpGen.generateKeyPair();
DHPublicKeyParameters pu2 = (DHPublicKeyParameters)pair.getPublic();
DHPrivateKeyParameters pv2 = (DHPrivateKeyParameters)pair.getPrivate();
checkKeySize(privateValueSize, pv2);
//
// two way
//
DHBasicAgreement e1 = new DHBasicAgreement();
DHBasicAgreement e2 = new DHBasicAgreement();
e1.init(pv1);
e2.init(pv2);
BigInteger k1 = e1.calculateAgreement(pu2);
BigInteger k2 = e2.calculateAgreement(pu1);
if (!k1.equals(k2))
{
fail("basic " + size + " bit 2-way test failed");
}
}