use of org.bouncycastle.crypto.generators.DHParametersGenerator in project robovm by robovm.
the class AlgorithmParameterGeneratorSpi method engineGenerateParameters.
protected AlgorithmParameters engineGenerateParameters() {
DHParametersGenerator pGen = new DHParametersGenerator();
if (random != null) {
pGen.init(strength, 20, random);
} else {
pGen.init(strength, 20, new SecureRandom());
}
DHParameters p = pGen.generateParameters();
AlgorithmParameters params;
try {
params = AlgorithmParameters.getInstance("DH", BouncyCastleProvider.PROVIDER_NAME);
params.init(new DHParameterSpec(p.getP(), p.getG(), l));
} catch (Exception e) {
throw new RuntimeException(e.getMessage());
}
return params;
}
use of org.bouncycastle.crypto.generators.DHParametersGenerator in project robovm by robovm.
the class KeyPairGeneratorSpi method generateKeyPair.
public KeyPair generateKeyPair() {
if (!initialised) {
Integer paramStrength = Integers.valueOf(strength);
if (params.containsKey(paramStrength)) {
param = (DHKeyGenerationParameters) params.get(paramStrength);
} else {
DHParameterSpec dhParams = BouncyCastleProvider.CONFIGURATION.getDHDefaultParameters(strength);
if (dhParams != null) {
param = new DHKeyGenerationParameters(random, new DHParameters(dhParams.getP(), dhParams.getG(), null, dhParams.getL()));
} else {
synchronized (lock) {
// our key size.
if (params.containsKey(paramStrength)) {
param = (DHKeyGenerationParameters) params.get(paramStrength);
} else {
DHParametersGenerator pGen = new DHParametersGenerator();
pGen.init(strength, certainty, random);
param = new DHKeyGenerationParameters(random, pGen.generateParameters());
params.put(paramStrength, param);
}
}
}
}
engine.init(param);
initialised = true;
}
AsymmetricCipherKeyPair pair = engine.generateKeyPair();
DHPublicKeyParameters pub = (DHPublicKeyParameters) pair.getPublic();
DHPrivateKeyParameters priv = (DHPrivateKeyParameters) pair.getPrivate();
return new KeyPair(new BCDHPublicKey(pub), new BCDHPrivateKey(priv));
}
Aggregations