use of com.github.zhenwei.core.crypto.generators.ElGamalParametersGenerator in project LinLong-Java by zhenwei1108.
the class KeyPairGeneratorSpi method generateKeyPair.
public KeyPair generateKeyPair() {
if (!initialised) {
DHParameterSpec dhParams = WeGooProvider.CONFIGURATION.getDHDefaultParameters(strength);
if (dhParams != null) {
param = new ElGamalKeyGenerationParameters(random, new ElGamalParameters(dhParams.getP(), dhParams.getG(), dhParams.getL()));
} else {
ElGamalParametersGenerator pGen = new ElGamalParametersGenerator();
pGen.init(strength, certainty, random);
param = new ElGamalKeyGenerationParameters(random, pGen.generateParameters());
}
engine.init(param);
initialised = true;
}
AsymmetricCipherKeyPair pair = engine.generateKeyPair();
ElGamalPublicKeyParameters pub = (ElGamalPublicKeyParameters) pair.getPublic();
ElGamalPrivateKeyParameters priv = (ElGamalPrivateKeyParameters) pair.getPrivate();
return new KeyPair(new BCElGamalPublicKey(pub), new BCElGamalPrivateKey(priv));
}
use of com.github.zhenwei.core.crypto.generators.ElGamalParametersGenerator in project LinLong-Java by zhenwei1108.
the class AlgorithmParameterGeneratorSpi method engineGenerateParameters.
protected AlgorithmParameters engineGenerateParameters() {
ElGamalParametersGenerator pGen = new ElGamalParametersGenerator();
if (random != null) {
pGen.init(strength, 20, random);
} else {
pGen.init(strength, 20, CryptoServicesRegistrar.getSecureRandom());
}
ElGamalParameters p = pGen.generateParameters();
AlgorithmParameters params;
try {
params = createParametersInstance("ElGamal");
params.init(new DHParameterSpec(p.getP(), p.getG(), l));
} catch (Exception e) {
throw new RuntimeException(e.getMessage());
}
return params;
}
Aggregations