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


Java DSAParametersGenerator.generateParameters方法代码示例

本文整理汇总了Java中org.bouncycastle.crypto.generators.DSAParametersGenerator.generateParameters方法的典型用法代码示例。如果您正苦于以下问题:Java DSAParametersGenerator.generateParameters方法的具体用法?Java DSAParametersGenerator.generateParameters怎么用?Java DSAParametersGenerator.generateParameters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bouncycastle.crypto.generators.DSAParametersGenerator的用法示例。


在下文中一共展示了DSAParametersGenerator.generateParameters方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: generateKeyPair

import org.bouncycastle.crypto.generators.DSAParametersGenerator; //导入方法依赖的package包/类
public KeyPair generateKeyPair()
{
    if (!initialised)
    {
        DSAParametersGenerator pGen = new DSAParametersGenerator();

        pGen.init(strength, certainty, random);
        param = new DSAKeyGenerationParameters(random, pGen.generateParameters());
        engine.init(param);
        initialised = true;
    }

    AsymmetricCipherKeyPair pair = engine.generateKeyPair();
    DSAPublicKeyParameters pub = (DSAPublicKeyParameters)pair.getPublic();
    DSAPrivateKeyParameters priv = (DSAPrivateKeyParameters)pair.getPrivate();

    return new KeyPair(new BCDSAPublicKey(pub),
        new BCDSAPrivateKey(priv));
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:20,代码来源:KeyPairGeneratorSpi.java

示例2: createAsymmetricCipherKeyPairGenerator

import org.bouncycastle.crypto.generators.DSAParametersGenerator; //导入方法依赖的package包/类
@Override
public AsymmetricCipherKeyPairGenerator createAsymmetricCipherKeyPairGenerator(final boolean initWithDefaults) {
	final DSAKeyPairGenerator generator = new DSAKeyPairGenerator();

	if (initWithDefaults) {
		/*
		 * How certain do we want to be that the chosen primes are really primes.
		 * <p>
		 * The higher this number, the more tests are done to make sure they are primes (and not composites).
		 * <p>
		 * See: <a href="http://crypto.stackexchange.com/questions/3114/what-is-the-correct-value-for-certainty-in-rsa-key-pair-generation">What is the correct value for “certainty” in RSA key pair generation?</a>
		 * and
		 * <a href="http://crypto.stackexchange.com/questions/3126/does-a-high-exponent-compensate-for-a-low-degree-of-certainty?lq=1">Does a high exponent compensate for a low degree of certainty?</a>
		 */
		final int certainty = 12;

		final SecureRandom random = new SecureRandom();

		final DSAParametersGenerator pGen = new DSAParametersGenerator();
		pGen.init(4096, certainty, random);
		final DSAParameters dsaParameters = pGen.generateParameters();
		final DSAKeyGenerationParameters dsaKeyGenerationParameters = new DSAKeyGenerationParameters(random, dsaParameters);
		generator.init(dsaKeyGenerationParameters);
	}
	return generator;
}
 
开发者ID:subshare,项目名称:subshare,代码行数:27,代码来源:DSAKeyPairGeneratorFactory.java

示例3: createDsaKeyGenerationParameters

import org.bouncycastle.crypto.generators.DSAParametersGenerator; //导入方法依赖的package包/类
private DSAKeyGenerationParameters createDsaKeyGenerationParameters(final CreatePgpKeyParam createPgpKeyParam) {
	/*
	 * How certain do we want to be that the chosen primes are really primes.
	 * <p>
	 * The higher this number, the more tests are done to make sure they are primes (and not composites).
	 * <p>
	 * See: <a href="http://crypto.stackexchange.com/questions/3114/what-is-the-correct-value-for-certainty-in-rsa-key-pair-generation">What is the correct value for “certainty” in RSA key pair generation?</a>
	 * and
	 * <a href="http://crypto.stackexchange.com/questions/3126/does-a-high-exponent-compensate-for-a-low-degree-of-certainty?lq=1">Does a high exponent compensate for a low degree of certainty?</a>
	 */
	final int certainty = 12;

	final SecureRandom random = getSecureRandom();

	final DSAParametersGenerator pGen = new DSAParametersGenerator();
	pGen.init(createPgpKeyParam.getStrength(), certainty, random);
	final DSAParameters dsaParameters = pGen.generateParameters();
	return new DSAKeyGenerationParameters(random, dsaParameters);
}
 
开发者ID:subshare,项目名称:subshare,代码行数:20,代码来源:BcWithLocalGnuPgPgp.java

示例4: getNewDSAParameterSpec

import org.bouncycastle.crypto.generators.DSAParametersGenerator; //导入方法依赖的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

示例5: engineGenerateParameters

import org.bouncycastle.crypto.generators.DSAParametersGenerator; //导入方法依赖的package包/类
protected AlgorithmParameters engineGenerateParameters()
     {
         DSAParametersGenerator pGen = new DSAParametersGenerator();

if ( random != null )
{
	pGen.init(strength, 20, random);
}
else
{
	pGen.init(strength, 20, new SecureRandom());
}

         DSAParameters p = pGen.generateParameters();

         AlgorithmParameters params;

         try
         {
             params = AlgorithmParameters.getInstance("DSA", BouncyCastleProvider.PROVIDER_NAME);
             params.init(new DSAParameterSpec(p.getP(), p.getQ(), p.getG()));
         }
         catch (Exception e)
         {
             throw new RuntimeException(e.getMessage());
         }

         return params;
     }
 
开发者ID:thangbn,项目名称:Direct-File-Downloader,代码行数:30,代码来源:JDKAlgorithmParameterGenerator.java

示例6: performTest

import org.bouncycastle.crypto.generators.DSAParametersGenerator; //导入方法依赖的package包/类
public void performTest()
{
    BigInteger              r = new BigInteger("68076202252361894315274692543577577550894681403");
    BigInteger              s = new BigInteger("1089214853334067536215539335472893651470583479365");
    DSAParametersGenerator  pGen = new DSAParametersGenerator();

    pGen.init(512, 80, random);

    DSAParameters           params = pGen.generateParameters();
    DSAValidationParameters pValid = params.getValidationParameters();

    if (pValid.getCounter() != 105)
    {
        fail("Counter wrong");
    }

    if (!pValue.equals(params.getP()) || !qValue.equals(params.getQ()))
    {
        fail("p or q wrong");
    }

    DSAKeyPairGenerator         dsaKeyGen = new DSAKeyPairGenerator();
    DSAKeyGenerationParameters  genParam = new DSAKeyGenerationParameters(keyRandom, params);

    dsaKeyGen.init(genParam);

    AsymmetricCipherKeyPair  pair = dsaKeyGen.generateKeyPair();

    ParametersWithRandom param = new ParametersWithRandom(pair.getPrivate(), keyRandom);

    DSASigner dsa = new DSASigner();

    dsa.init(true, param);

    byte[] message = BigIntegers.asUnsignedByteArray(new BigInteger("968236873715988614170569073515315707566766479517"));
    BigInteger[] sig = dsa.generateSignature(message);

    if (!r.equals(sig[0]))
    {
        fail("r component wrong.", r, sig[0]);
    }

    if (!s.equals(sig[1]))
    {
        fail("s component wrong.", s, sig[1]);
    }

    dsa.init(false, pair.getPublic());

    if (!dsa.verifySignature(message, sig[0], sig[1]))
    {
        fail("verification fails");
    }

    dsa2Test1();
    dsa2Test2();
    dsa2Test3();
    dsa2Test4();
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:60,代码来源:DSATest.java

示例7: checkCreation2

import org.bouncycastle.crypto.generators.DSAParametersGenerator; //导入方法依赖的package包/类
/**
 * we generate a self signed certificate for the sake of testing - DSA
 */
public void checkCreation2()
    throws Exception
{
    //
    // set up the keys
    //
    AsymmetricKeyParameter          privKey;
    AsymmetricKeyParameter          pubKey;

    AsymmetricCipherKeyPairGenerator kpg = new DSAKeyPairGenerator();
    BigInteger              r = new BigInteger("68076202252361894315274692543577577550894681403");
    BigInteger              s = new BigInteger("1089214853334067536215539335472893651470583479365");
    DSAParametersGenerator pGen = new DSAParametersGenerator();

    pGen.init(512, 80, new SecureRandom());

    DSAParameters params = pGen.generateParameters();
    DSAKeyGenerationParameters genParam = new DSAKeyGenerationParameters(new SecureRandom(), params);

    kpg.init(genParam);

    AsymmetricCipherKeyPair pair = kpg.generateKeyPair();

    privKey = (AsymmetricKeyParameter)pair.getPrivate();
    pubKey = (AsymmetricKeyParameter)pair.getPublic();

    //
    // distinguished name table.
    //
    X500NameBuilder builder = createStdBuilder();

    //
    // extensions
    //

    //
    // create the certificate - version 3
    //
    AlgorithmIdentifier sigAlgId = sigAlgFinder.find("SHA1withDSA");
    AlgorithmIdentifier digAlgId = digAlgFinder.find(sigAlgId);

    ContentSigner sigGen = new BcDSAContentSignerBuilder(sigAlgId, digAlgId).build(privKey);
    X509v3CertificateBuilder  certGen = new BcX509v3CertificateBuilder(builder.build(),BigInteger.valueOf(1),new Date(System.currentTimeMillis() - 50000),new Date(System.currentTimeMillis() + 50000),builder.build(),pubKey);


    X509CertificateHolder cert = certGen.build(sigGen);

    assertTrue(cert.isValidOn(new Date()));

    assertTrue(cert.isSignatureValid(new BcDSAContentVerifierProviderBuilder(digAlgFinder).build(pubKey)));


    //
    // create the certificate - version 1
    //
    sigAlgId = sigAlgFinder.find("SHA1withDSA");
    digAlgId = digAlgFinder.find(sigAlgId);

    sigGen = new BcDSAContentSignerBuilder(sigAlgId, digAlgId).build(privKey);
    X509v1CertificateBuilder  certGen1 = new BcX509v1CertificateBuilder(builder.build(),BigInteger.valueOf(1),new Date(System.currentTimeMillis() - 50000),new Date(System.currentTimeMillis() + 50000),builder.build(),pubKey);

    cert = certGen1.build(sigGen);

    assertTrue(cert.isValidOn(new Date()));

    assertTrue(cert.isSignatureValid(new BcDSAContentVerifierProviderBuilder(digAlgFinder).build(pubKey)));

    ByteArrayInputStream bIn = new ByteArrayInputStream(cert.getEncoded());
    CertificateFactory fact = CertificateFactory.getInstance("X.509");

    X509Certificate x509cert = (X509Certificate)fact.generateCertificate(bIn);

        //System.out.println(cert);
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:78,代码来源:BcCertTest.java

示例8: performTest

import org.bouncycastle.crypto.generators.DSAParametersGenerator; //导入方法依赖的package包/类
public void performTest()
{
    BigInteger              r = new BigInteger("68076202252361894315274692543577577550894681403");
    BigInteger              s = new BigInteger("1089214853334067536215539335472893651470583479365");
    DSAParametersGenerator  pGen = new DSAParametersGenerator();

    pGen.init(512, 20, random);

    DSAParameters           params = pGen.generateParameters();
    DSAValidationParameters pValid = params.getValidationParameters();

    if (pValid.getCounter() != 105)
    {
        fail("Counter wrong");
    }

    if (!pValue.equals(params.getP()) || !qValue.equals(params.getQ()))
    {
        fail("p or q wrong");
    }

    DSAKeyPairGenerator         dsaKeyGen = new DSAKeyPairGenerator();
    DSAKeyGenerationParameters  genParam = new DSAKeyGenerationParameters(keyRandom, params);

    dsaKeyGen.init(genParam);

    AsymmetricCipherKeyPair  pair = dsaKeyGen.generateKeyPair();

    ParametersWithRandom param = new ParametersWithRandom(pair.getPrivate(), keyRandom);

    DSASigner dsa = new DSASigner();

    dsa.init(true, param);

    byte[] message = BigIntegers.asUnsignedByteArray(new BigInteger("968236873715988614170569073515315707566766479517"));
    BigInteger[] sig = dsa.generateSignature(message);

    if (!r.equals(sig[0]))
    {
        fail("r component wrong.", r, sig[0]);
    }

    if (!s.equals(sig[1]))
    {
        fail("s component wrong.", s, sig[1]);
    }

    dsa.init(false, pair.getPublic());

    if (!dsa.verifySignature(message, sig[0], sig[1]))
    {
        fail("verification fails");
    }

    //dsa2Test1();
    //dsa2Test2();
    //dsa2Test3();
    //dsa2Test4();
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:60,代码来源:DSATest.java


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