本文整理汇总了Java中org.bouncycastle.crypto.params.DSAParameters.getQ方法的典型用法代码示例。如果您正苦于以下问题:Java DSAParameters.getQ方法的具体用法?Java DSAParameters.getQ怎么用?Java DSAParameters.getQ使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.crypto.params.DSAParameters
的用法示例。
在下文中一共展示了DSAParameters.getQ方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateKeyPair
import org.bouncycastle.crypto.params.DSAParameters; //导入方法依赖的package包/类
public AsymmetricCipherKeyPair generateKeyPair()
{
BigInteger p, q, g, x, y;
DSAParameters dsaParams = param.getParameters();
SecureRandom random = param.getRandom();
q = dsaParams.getQ();
p = dsaParams.getP();
g = dsaParams.getG();
do
{
x = new BigInteger(160, random);
}
while (x.equals(ZERO) || x.compareTo(q) >= 0);
//
// calculate the public key.
//
y = g.modPow(x, p);
return new AsymmetricCipherKeyPair(
new DSAPublicKeyParameters(y, dsaParams),
new DSAPrivateKeyParameters(x, dsaParams));
}
示例2: generateDSAKeypair
import org.bouncycastle.crypto.params.DSAParameters; //导入方法依赖的package包/类
public static KeyPair generateDSAKeypair(DSAParameters dsaParams, SecureRandom random)
throws NoSuchAlgorithmException, NoSuchProviderException,
InvalidAlgorithmParameterException {
DSAParameterSpec dsaParamSpec = new DSAParameterSpec(dsaParams.getP(), dsaParams.getQ(),
dsaParams.getG());
KeyPairGenerator kpGen = getKeyPairGenerator("DSA");
synchronized (kpGen) {
kpGen.initialize(dsaParamSpec, random);
return kpGen.generateKeyPair();
}
}
示例3: getNewDSAParameterSpec
import org.bouncycastle.crypto.params.DSAParameters; //导入方法依赖的package包/类
public static DSAParameterSpec getNewDSAParameterSpec(int plength, int qlength,
SecureRandom random) {
final int certainty = 80;
SecureRandom tmpRandom = (random == null) ? new SecureRandom() : random;
DSAParametersGenerator paramGen = new DSAParametersGenerator(new SHA512Digest());
DSAParameterGenerationParameters genParams = new DSAParameterGenerationParameters(
plength, qlength, certainty, tmpRandom);
paramGen.init(genParams);
DSAParameters dsaParams = paramGen.generateParameters();
return new DSAParameterSpec(dsaParams.getP(), dsaParams.getQ(), dsaParams.getG());
}
示例4: generateSignature
import org.bouncycastle.crypto.params.DSAParameters; //导入方法依赖的package包/类
/**
* generate a signature for the given message using the key we were
* initialised with. For conventional DSA the message should be a SHA-1
* hash of the message of interest.
*
* @param message the message that will be verified later.
*/
public BigInteger[] generateSignature(
byte[] message)
{
DSAParameters params = key.getParameters();
BigInteger q = params.getQ();
BigInteger m = calculateE(q, message);
BigInteger x = ((DSAPrivateKeyParameters)key).getX();
if (kCalculator.isDeterministic())
{
kCalculator.init(q, x, message);
}
else
{
kCalculator.init(q, random);
}
BigInteger k = kCalculator.nextK();
BigInteger r = params.getG().modPow(k, params.getP()).mod(q);
k = k.modInverse(q).multiply(m.add(x.multiply(r)));
BigInteger s = k.mod(q);
return new BigInteger[]{ r, s };
}
示例5: verifySignature
import org.bouncycastle.crypto.params.DSAParameters; //导入方法依赖的package包/类
/**
* return true if the value r and s represent a DSA signature for
* the passed in message for standard DSA the message should be a
* SHA-1 hash of the real message to be verified.
*/
public boolean verifySignature(
byte[] message,
BigInteger r,
BigInteger s)
{
DSAParameters params = key.getParameters();
BigInteger q = params.getQ();
BigInteger m = calculateE(q, message);
BigInteger zero = BigInteger.valueOf(0);
if (zero.compareTo(r) >= 0 || q.compareTo(r) <= 0)
{
return false;
}
if (zero.compareTo(s) >= 0 || q.compareTo(s) <= 0)
{
return false;
}
BigInteger w = s.modInverse(q);
BigInteger u1 = m.multiply(w).mod(q);
BigInteger u2 = r.multiply(w).mod(q);
BigInteger p = params.getP();
u1 = params.getG().modPow(u1, p);
u2 = ((DSAPublicKeyParameters)key).getY().modPow(u2, p);
BigInteger v = u1.multiply(u2).mod(p).mod(q);
return v.equals(r);
}