📄 dhkeypairgenerator.java
字号:
package org.bouncycastle.crypto.generators;import org.bouncycastle.crypto.AsymmetricCipherKeyPair;import org.bouncycastle.crypto.AsymmetricCipherKeyPairGenerator;import org.bouncycastle.crypto.KeyGenerationParameters;import org.bouncycastle.crypto.params.DHKeyGenerationParameters;import org.bouncycastle.crypto.params.DHParameters;import org.bouncycastle.crypto.params.DHPrivateKeyParameters;import org.bouncycastle.crypto.params.DHPublicKeyParameters;import java.math.BigInteger;/** * a Diffie-Helman key pair generator. * * This generates keys consistent for use in the MTI/A0 key agreement protocol * as described in "Handbook of Applied Cryptography", Pages 516-519. */public class DHKeyPairGenerator implements AsymmetricCipherKeyPairGenerator{ private DHKeyGeneratorHelper helper = DHKeyGeneratorHelper.INSTANCE; private DHKeyGenerationParameters param; public void init( KeyGenerationParameters param) { this.param = (DHKeyGenerationParameters)param; } public AsymmetricCipherKeyPair generateKeyPair() { BigInteger p, x, y; DHParameters dhParams = param.getParameters(); p = dhParams.getP(); x = helper.calculatePrivate(p, param.getRandom(), dhParams.getL()); y = helper.calculatePublic(p, dhParams.getG(), x); return new AsymmetricCipherKeyPair( new DHPublicKeyParameters(y, dhParams), new DHPrivateKeyParameters(x, dhParams)); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -