本文整理汇总了Java中org.bouncycastle.crypto.generators.DHKeyPairGenerator.init方法的典型用法代码示例。如果您正苦于以下问题:Java DHKeyPairGenerator.init方法的具体用法?Java DHKeyPairGenerator.init怎么用?Java DHKeyPairGenerator.init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.crypto.generators.DHKeyPairGenerator
的用法示例。
在下文中一共展示了DHKeyPairGenerator.init方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateServerKeyExchange
import org.bouncycastle.crypto.generators.DHKeyPairGenerator; //导入方法依赖的package包/类
public byte[] generateServerKeyExchange()
throws IOException
{
if (this.dhParameters == null)
{
throw new TlsFatalAlert(AlertDescription.internal_error);
}
ByteArrayOutputStream buf = new ByteArrayOutputStream();
DHKeyPairGenerator kpg = new DHKeyPairGenerator();
kpg.init(new DHKeyGenerationParameters(context.getSecureRandom(), this.dhParameters));
AsymmetricCipherKeyPair kp = kpg.generateKeyPair();
BigInteger Ys = ((DHPublicKeyParameters)kp.getPublic()).getY();
TlsDHUtils.writeDHParameter(dhParameters.getP(), buf);
TlsDHUtils.writeDHParameter(dhParameters.getG(), buf);
TlsDHUtils.writeDHParameter(Ys, buf);
byte[] digestInput = buf.toByteArray();
Digest d = new CombinedHash();
SecurityParameters securityParameters = context.getSecurityParameters();
d.update(securityParameters.clientRandom, 0, securityParameters.clientRandom.length);
d.update(securityParameters.serverRandom, 0, securityParameters.serverRandom.length);
d.update(digestInput, 0, digestInput.length);
byte[] hash = new byte[d.getDigestSize()];
d.doFinal(hash, 0);
byte[] sigBytes = serverCredentials.generateCertificateSignature(hash);
/*
* TODO RFC 5246 4.7. digitally-signed element needs SignatureAndHashAlgorithm prepended from TLS 1.2
*/
TlsUtils.writeOpaque16(sigBytes, buf);
return buf.toByteArray();
}
示例2: calculateMessage
import org.bouncycastle.crypto.generators.DHKeyPairGenerator; //导入方法依赖的package包/类
/**
* calculate our initial message.
*/
public BigInteger calculateMessage()
{
DHKeyPairGenerator dhGen = new DHKeyPairGenerator();
dhGen.init(new DHKeyGenerationParameters(random, dhParams));
AsymmetricCipherKeyPair dhPair = dhGen.generateKeyPair();
this.privateValue = ((DHPrivateKeyParameters)dhPair.getPrivate()).getX();
return ((DHPublicKeyParameters)dhPair.getPublic()).getY();
}
示例3: getDHKeyPairGenerator
import org.bouncycastle.crypto.generators.DHKeyPairGenerator; //导入方法依赖的package包/类
private DHKeyPairGenerator getDHKeyPairGenerator(
BigInteger g,
BigInteger p)
{
DHParameters dhParams = new DHParameters(p, g);
DHKeyGenerationParameters params = new DHKeyGenerationParameters(new SecureRandom(), dhParams);
DHKeyPairGenerator kpGen = new DHKeyPairGenerator();
kpGen.init(params);
return kpGen;
}