Search in sources :

Example 1 with DSAParameterGenerationParameters

use of org.bouncycastle.crypto.params.DSAParameterGenerationParameters in project robovm by robovm.

the class AlgorithmParameterGeneratorSpi method engineGenerateParameters.

protected AlgorithmParameters engineGenerateParameters() {
    DSAParametersGenerator pGen;
    if (strength <= 1024) {
        pGen = new DSAParametersGenerator();
    } else {
        pGen = new DSAParametersGenerator(new SHA256Digest());
    }
    if (random == null) {
        random = new SecureRandom();
    }
    if (strength == 1024) {
        params = new DSAParameterGenerationParameters(1024, 160, 80, random);
        pGen.init(params);
    } else if (strength > 1024) {
        params = new DSAParameterGenerationParameters(strength, 256, 80, random);
        pGen.init(params);
    } else {
        pGen.init(strength, 20, random);
    }
    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;
}
Also used : DSAParametersGenerator(org.bouncycastle.crypto.generators.DSAParametersGenerator) DSAParameterSpec(java.security.spec.DSAParameterSpec) SHA256Digest(org.bouncycastle.crypto.digests.SHA256Digest) DSAParameterGenerationParameters(org.bouncycastle.crypto.params.DSAParameterGenerationParameters) SecureRandom(java.security.SecureRandom) DSAParameters(org.bouncycastle.crypto.params.DSAParameters) InvalidParameterException(java.security.InvalidParameterException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) AlgorithmParameters(java.security.AlgorithmParameters)

Example 2 with DSAParameterGenerationParameters

use of org.bouncycastle.crypto.params.DSAParameterGenerationParameters in project xipki by xipki.

the class DSAParameterCache method getNewDSAParameterSpec.

// CHECKSTYLE:SKIP
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());
}
Also used : DSAParametersGenerator(org.bouncycastle.crypto.generators.DSAParametersGenerator) SHA512Digest(org.bouncycastle.crypto.digests.SHA512Digest) DSAParameterSpec(java.security.spec.DSAParameterSpec) DSAParameterGenerationParameters(org.bouncycastle.crypto.params.DSAParameterGenerationParameters) SecureRandom(java.security.SecureRandom) DSAParameters(org.bouncycastle.crypto.params.DSAParameters)

Aggregations

SecureRandom (java.security.SecureRandom)2 DSAParameterSpec (java.security.spec.DSAParameterSpec)2 DSAParametersGenerator (org.bouncycastle.crypto.generators.DSAParametersGenerator)2 DSAParameterGenerationParameters (org.bouncycastle.crypto.params.DSAParameterGenerationParameters)2 DSAParameters (org.bouncycastle.crypto.params.DSAParameters)2 AlgorithmParameters (java.security.AlgorithmParameters)1 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)1 InvalidParameterException (java.security.InvalidParameterException)1 SHA256Digest (org.bouncycastle.crypto.digests.SHA256Digest)1 SHA512Digest (org.bouncycastle.crypto.digests.SHA512Digest)1