use of com.github.zhenwei.core.crypto.params.DSAParameterGenerationParameters in project LinLong-Java by zhenwei1108.
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 = CryptoServicesRegistrar.getSecureRandom();
}
int certainty = PrimeCertaintyCalculator.getDefaultCertainty(strength);
if (strength == 1024) {
params = new DSAParameterGenerationParameters(1024, 160, certainty, random);
pGen.init(params);
} else if (strength > 1024) {
params = new DSAParameterGenerationParameters(strength, 256, certainty, random);
pGen.init(params);
} else {
pGen.init(strength, certainty, random);
}
DSAParameters p = pGen.generateParameters();
AlgorithmParameters params;
try {
params = createParametersInstance("DSA");
params.init(new DSAParameterSpec(p.getP(), p.getQ(), p.getG()));
} catch (Exception e) {
throw new RuntimeException(e.getMessage());
}
return params;
}
use of com.github.zhenwei.core.crypto.params.DSAParameterGenerationParameters 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));
}
Aggregations