本文整理汇总了Java中org.bouncycastle.crypto.params.DHParameters.getG方法的典型用法代码示例。如果您正苦于以下问题:Java DHParameters.getG方法的具体用法?Java DHParameters.getG怎么用?Java DHParameters.getG使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.crypto.params.DHParameters
的用法示例。
在下文中一共展示了DHParameters.getG方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validateDHPublicKey
import org.bouncycastle.crypto.params.DHParameters; //导入方法依赖的package包/类
public static DHPublicKeyParameters validateDHPublicKey(DHPublicKeyParameters key)
throws IOException
{
BigInteger Y = key.getY();
DHParameters params = key.getParameters();
BigInteger p = params.getP();
BigInteger g = params.getG();
if (!p.isProbablePrime(2))
{
throw new TlsFatalAlert(AlertDescription.illegal_parameter);
}
if (g.compareTo(TWO) < 0 || g.compareTo(p.subtract(TWO)) > 0)
{
throw new TlsFatalAlert(AlertDescription.illegal_parameter);
}
if (Y.compareTo(TWO) < 0 || Y.compareTo(p.subtract(ONE)) > 0)
{
throw new TlsFatalAlert(AlertDescription.illegal_parameter);
}
// TODO See RFC 2631 for more discussion of Diffie-Hellman validation
return key;
}
示例2: generateKeyPair
import org.bouncycastle.crypto.params.DHParameters; //导入方法依赖的package包/类
public AsymmetricCipherKeyPair generateKeyPair()
{
BigInteger p, g, x, y;
int qLength = param.getStrength() - 1;
DHParameters dhParams = param.getParameters();
p = dhParams.getP();
g = dhParams.getG();
//
// calculate the private key
//
x = new BigInteger(qLength, param.getRandom());
//
// calculate the public key.
//
y = g.modPow(x, p);
return new AsymmetricCipherKeyPair(
new DHPublicKeyParameters(y, dhParams),
new DHPrivateKeyParameters(x, dhParams));
}
示例3: generateKeyPair
import org.bouncycastle.crypto.params.DHParameters; //导入方法依赖的package包/类
public AsymmetricCipherKeyPair generateKeyPair()
{
BigInteger p, g, x, y;
int qLength = param.getStrength() - 1;
DHParameters dhParams = param.getParameters();
p = dhParams.getP();
g = dhParams.getG();
//
// calculate the private key
//
x = new BigInteger(qLength, param.getRandom());
//
// calculate the public key.
//
y = g.modPow(x, p);
return new AsymmetricCipherKeyPair(
new DHPublicKeyParameters(y, dhParams),
new DHPrivateKeyParameters(x, dhParams));
}
示例4: validateDHParameters
import org.bouncycastle.crypto.params.DHParameters; //导入方法依赖的package包/类
public static DHParameters validateDHParameters(DHParameters params) throws IOException
{
BigInteger p = params.getP();
BigInteger g = params.getG();
if (!p.isProbablePrime(2))
{
throw new TlsFatalAlert(AlertDescription.illegal_parameter);
}
if (g.compareTo(TWO) < 0 || g.compareTo(p.subtract(TWO)) > 0)
{
throw new TlsFatalAlert(AlertDescription.illegal_parameter);
}
return params;
}
示例5: validateDHPublicKey
import org.bouncycastle.crypto.params.DHParameters; //导入方法依赖的package包/类
public static DHPublicKeyParameters validateDHPublicKey(DHPublicKeyParameters key) throws IOException
{
BigInteger Y = key.getY();
DHParameters params = key.getParameters();
BigInteger p = params.getP();
BigInteger g = params.getG();
if (!p.isProbablePrime(2))
{
throw new TlsFatalAlert(AlertDescription.illegal_parameter);
}
if (g.compareTo(TWO) < 0 || g.compareTo(p.subtract(TWO)) > 0)
{
throw new TlsFatalAlert(AlertDescription.illegal_parameter);
}
if (Y.compareTo(TWO) < 0 || Y.compareTo(p.subtract(TWO)) > 0)
{
throw new TlsFatalAlert(AlertDescription.illegal_parameter);
}
// TODO See RFC 2631 for more discussion of Diffie-Hellman validation
return key;
}
示例6: validateDHPublicKey
import org.bouncycastle.crypto.params.DHParameters; //导入方法依赖的package包/类
public static DHPublicKeyParameters validateDHPublicKey(DHPublicKeyParameters key) throws IOException
{
BigInteger Y = key.getY();
DHParameters params = key.getParameters();
BigInteger p = params.getP();
BigInteger g = params.getG();
if (!p.isProbablePrime(2))
{
throw new TlsFatalAlert(AlertDescription.illegal_parameter);
}
if (g.compareTo(TWO) < 0 || g.compareTo(p.subtract(TWO)) > 0)
{
throw new TlsFatalAlert(AlertDescription.illegal_parameter);
}
if (Y.compareTo(TWO) < 0 || Y.compareTo(p.subtract(ONE)) > 0)
{
throw new TlsFatalAlert(AlertDescription.illegal_parameter);
}
// TODO See RFC 2631 for more discussion of Diffie-Hellman validation
return key;
}
示例7: generateParameters
import org.bouncycastle.crypto.params.DHParameters; //导入方法依赖的package包/类
public CramerShoupParameters generateParameters(DHParameters dhParams)
{
BigInteger p = dhParams.getP();
BigInteger g1 = dhParams.getG();
// now we just need a second generator
BigInteger g2 = ParametersHelper.selectGenerator(p, random);
while (g1.equals(g2))
{
g2 = ParametersHelper.selectGenerator(p, random);
}
return new CramerShoupParameters(p, g1, g2, new SHA256Digest());
}
示例8: testWithRandomParams
import org.bouncycastle.crypto.params.DHParameters; //导入方法依赖的package包/类
private void testWithRandomParams(int bits) throws CryptoException
{
DHParametersGenerator paramGen = new DHParametersGenerator();
paramGen.init(bits, 25, random);
DHParameters parameters = paramGen.generateParameters();
BigInteger g = parameters.getG();
BigInteger p = parameters.getP();
testMutualVerification(p, g);
}
示例9: validateDHPublicKey
import org.bouncycastle.crypto.params.DHParameters; //导入方法依赖的package包/类
private DHPublicKeyParameters validateDHPublicKey(DHPublicKeyParameters key) throws IOException
{
BigInteger Y = key.getY();
DHParameters params = key.getParameters();
BigInteger p = params.getP();
BigInteger g = params.getG();
if (!p.isProbablePrime(2))
{
handler.failWithError(TlsProtocolHandler.AL_fatal,
TlsProtocolHandler.AP_illegal_parameter);
}
if (g.compareTo(TWO) < 0 || g.compareTo(p.subtract(TWO)) > 0)
{
handler.failWithError(TlsProtocolHandler.AL_fatal,
TlsProtocolHandler.AP_illegal_parameter);
}
if (Y.compareTo(TWO) < 0 || Y.compareTo(p.subtract(ONE)) > 0)
{
handler.failWithError(TlsProtocolHandler.AL_fatal,
TlsProtocolHandler.AP_illegal_parameter);
}
// TODO See RFC 2631 for more discussion of Diffie-Hellman validation
return key;
}
示例10: PaceDH
import org.bouncycastle.crypto.params.DHParameters; //导入方法依赖的package包/类
public PaceDH(DHParameters dhParameters) {
g = dhParameters.getG();
p = dhParameters.getP();
Random rnd = new Random();
randomGenerator.setSeed(rnd.nextLong());
}