Search in sources :

Example 1 with DSAParametersGenerator

use of org.bouncycastle.crypto.generators.DSAParametersGenerator in project robovm by robovm.

the class KeyPairGeneratorSpi method generateKeyPair.

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));
}
Also used : DSAParametersGenerator(org.bouncycastle.crypto.generators.DSAParametersGenerator) DSAPublicKeyParameters(org.bouncycastle.crypto.params.DSAPublicKeyParameters) KeyPair(java.security.KeyPair) AsymmetricCipherKeyPair(org.bouncycastle.crypto.AsymmetricCipherKeyPair) DSAKeyGenerationParameters(org.bouncycastle.crypto.params.DSAKeyGenerationParameters) DSAPrivateKeyParameters(org.bouncycastle.crypto.params.DSAPrivateKeyParameters) AsymmetricCipherKeyPair(org.bouncycastle.crypto.AsymmetricCipherKeyPair)

Example 2 with DSAParametersGenerator

use of org.bouncycastle.crypto.generators.DSAParametersGenerator 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)

Aggregations

DSAParametersGenerator (org.bouncycastle.crypto.generators.DSAParametersGenerator)2 AlgorithmParameters (java.security.AlgorithmParameters)1 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)1 InvalidParameterException (java.security.InvalidParameterException)1 KeyPair (java.security.KeyPair)1 SecureRandom (java.security.SecureRandom)1 DSAParameterSpec (java.security.spec.DSAParameterSpec)1 AsymmetricCipherKeyPair (org.bouncycastle.crypto.AsymmetricCipherKeyPair)1 SHA256Digest (org.bouncycastle.crypto.digests.SHA256Digest)1 DSAKeyGenerationParameters (org.bouncycastle.crypto.params.DSAKeyGenerationParameters)1 DSAParameterGenerationParameters (org.bouncycastle.crypto.params.DSAParameterGenerationParameters)1 DSAParameters (org.bouncycastle.crypto.params.DSAParameters)1 DSAPrivateKeyParameters (org.bouncycastle.crypto.params.DSAPrivateKeyParameters)1 DSAPublicKeyParameters (org.bouncycastle.crypto.params.DSAPublicKeyParameters)1