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;
}
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));
}
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;
}
}
Aggregations