Search in sources :

Example 1 with DSAKeyGenerationParameters

use of com.github.zhenwei.core.crypto.params.DSAKeyGenerationParameters in project LinLong-Java by zhenwei1108.

the class KeyPairGeneratorSpi method initialize.

public void initialize(AlgorithmParameterSpec params, SecureRandom random) throws InvalidAlgorithmParameterException {
    if (!(params instanceof DSAParameterSpec)) {
        throw new InvalidAlgorithmParameterException("parameter object not a DSAParameterSpec");
    }
    DSAParameterSpec dsaParams = (DSAParameterSpec) params;
    param = new DSAKeyGenerationParameters(random, new DSAParameters(dsaParams.getP(), dsaParams.getQ(), dsaParams.getG()));
    engine.init(param);
    initialised = true;
}
Also used : DSAParameterSpec(java.security.spec.DSAParameterSpec) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) DSAKeyGenerationParameters(com.github.zhenwei.core.crypto.params.DSAKeyGenerationParameters) DSAParameters(com.github.zhenwei.core.crypto.params.DSAParameters)

Example 2 with DSAKeyGenerationParameters

use of com.github.zhenwei.core.crypto.params.DSAKeyGenerationParameters in project LinLong-Java by zhenwei1108.

the class KeyPairGeneratorSpi method generateKeyPair.

public KeyPair generateKeyPair() {
    if (!initialised) {
        Integer paramStrength = Integers.valueOf(strength);
        if (params.containsKey(paramStrength)) {
            param = (DSAKeyGenerationParameters) params.get(paramStrength);
        } else {
            synchronized (lock) {
                // our key size.
                if (params.containsKey(paramStrength)) {
                    param = (DSAKeyGenerationParameters) params.get(paramStrength);
                } else {
                    DSAParametersGenerator pGen;
                    DSAParameterGenerationParameters dsaParams;
                    int certainty = PrimeCertaintyCalculator.getDefaultCertainty(strength);
                    // For legacy keysize that is less than 1024-bit, we just use the 186-2 style parameters
                    if (strength == 1024) {
                        pGen = new DSAParametersGenerator();
                        if (Properties.isOverrideSet("org.bouncycastle.dsa.FIPS186-2for1024bits")) {
                            pGen.init(strength, certainty, random);
                        } else {
                            dsaParams = new DSAParameterGenerationParameters(1024, 160, certainty, random);
                            pGen.init(dsaParams);
                        }
                    } else if (strength > 1024) {
                        dsaParams = new DSAParameterGenerationParameters(strength, 256, certainty, random);
                        pGen = new DSAParametersGenerator(new SHA256Digest());
                        pGen.init(dsaParams);
                    } else {
                        pGen = new DSAParametersGenerator();
                        pGen.init(strength, certainty, random);
                    }
                    param = new DSAKeyGenerationParameters(random, pGen.generateParameters());
                    params.put(paramStrength, param);
                }
            }
        }
        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(com.github.zhenwei.core.crypto.generators.DSAParametersGenerator) DSAPublicKeyParameters(com.github.zhenwei.core.crypto.params.DSAPublicKeyParameters) KeyPair(java.security.KeyPair) AsymmetricCipherKeyPair(com.github.zhenwei.core.crypto.AsymmetricCipherKeyPair) SHA256Digest(com.github.zhenwei.core.crypto.digests.SHA256Digest) DSAParameterGenerationParameters(com.github.zhenwei.core.crypto.params.DSAParameterGenerationParameters) DSAKeyGenerationParameters(com.github.zhenwei.core.crypto.params.DSAKeyGenerationParameters) DSAPrivateKeyParameters(com.github.zhenwei.core.crypto.params.DSAPrivateKeyParameters) AsymmetricCipherKeyPair(com.github.zhenwei.core.crypto.AsymmetricCipherKeyPair)

Example 3 with DSAKeyGenerationParameters

use of com.github.zhenwei.core.crypto.params.DSAKeyGenerationParameters in project LinLong-Java by zhenwei1108.

the class KeyPairGeneratorSpi method initialize.

public void initialize(int strength, SecureRandom random) {
    if (strength < 512 || strength > 4096 || ((strength < 1024) && strength % 64 != 0) || (strength >= 1024 && strength % 1024 != 0)) {
        throw new InvalidParameterException("strength must be from 512 - 4096 and a multiple of 1024 above 1024");
    }
    DSAParameterSpec spec = WeGooProvider.CONFIGURATION.getDSADefaultParameters(strength);
    if (spec != null) {
        param = new DSAKeyGenerationParameters(random, new DSAParameters(spec.getP(), spec.getQ(), spec.getG()));
        engine.init(param);
        this.initialised = true;
    } else {
        this.strength = strength;
        this.random = random;
        this.initialised = false;
    }
}
Also used : InvalidParameterException(java.security.InvalidParameterException) DSAParameterSpec(java.security.spec.DSAParameterSpec) DSAKeyGenerationParameters(com.github.zhenwei.core.crypto.params.DSAKeyGenerationParameters) DSAParameters(com.github.zhenwei.core.crypto.params.DSAParameters)

Aggregations

DSAKeyGenerationParameters (com.github.zhenwei.core.crypto.params.DSAKeyGenerationParameters)3 DSAParameters (com.github.zhenwei.core.crypto.params.DSAParameters)2 DSAParameterSpec (java.security.spec.DSAParameterSpec)2 AsymmetricCipherKeyPair (com.github.zhenwei.core.crypto.AsymmetricCipherKeyPair)1 SHA256Digest (com.github.zhenwei.core.crypto.digests.SHA256Digest)1 DSAParametersGenerator (com.github.zhenwei.core.crypto.generators.DSAParametersGenerator)1 DSAParameterGenerationParameters (com.github.zhenwei.core.crypto.params.DSAParameterGenerationParameters)1 DSAPrivateKeyParameters (com.github.zhenwei.core.crypto.params.DSAPrivateKeyParameters)1 DSAPublicKeyParameters (com.github.zhenwei.core.crypto.params.DSAPublicKeyParameters)1 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)1 InvalidParameterException (java.security.InvalidParameterException)1 KeyPair (java.security.KeyPair)1