当前位置: 首页>>代码示例>>Java>>正文


Java DSAParameters.getQ方法代码示例

本文整理汇总了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));
}
 
开发者ID:thangbn,项目名称:Direct-File-Downloader,代码行数:26,代码来源:DSAKeyPairGenerator.java

示例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();
    }
}
 
开发者ID:xipki,项目名称:xitk,代码行数:12,代码来源:KeyUtil.java

示例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());
}
 
开发者ID:xipki,项目名称:xitk,代码行数:12,代码来源:DSAParameterCache.java

示例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 };
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:35,代码来源:DSASigner.java

示例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);
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:39,代码来源:DSASigner.java


注:本文中的org.bouncycastle.crypto.params.DSAParameters.getQ方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。