Search in sources :

Example 1 with DHKeyGenerationParameters

use of org.bouncycastle.crypto.params.DHKeyGenerationParameters in project robovm by robovm.

the class KeyPairGeneratorSpi method initialize.

public void initialize(AlgorithmParameterSpec params, SecureRandom random) throws InvalidAlgorithmParameterException {
    if (!(params instanceof DHParameterSpec)) {
        throw new InvalidAlgorithmParameterException("parameter object not a DHParameterSpec");
    }
    DHParameterSpec dhParams = (DHParameterSpec) params;
    param = new DHKeyGenerationParameters(random, new DHParameters(dhParams.getP(), dhParams.getG(), null, dhParams.getL()));
    engine.init(param);
    initialised = true;
}
Also used : InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) DHParameters(org.bouncycastle.crypto.params.DHParameters) DHKeyGenerationParameters(org.bouncycastle.crypto.params.DHKeyGenerationParameters) DHParameterSpec(javax.crypto.spec.DHParameterSpec)

Example 2 with DHKeyGenerationParameters

use of org.bouncycastle.crypto.params.DHKeyGenerationParameters 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));
}
Also used : KeyPair(java.security.KeyPair) AsymmetricCipherKeyPair(org.bouncycastle.crypto.AsymmetricCipherKeyPair) DHPublicKeyParameters(org.bouncycastle.crypto.params.DHPublicKeyParameters) DHParameters(org.bouncycastle.crypto.params.DHParameters) DHPrivateKeyParameters(org.bouncycastle.crypto.params.DHPrivateKeyParameters) DHKeyGenerationParameters(org.bouncycastle.crypto.params.DHKeyGenerationParameters) DHParameterSpec(javax.crypto.spec.DHParameterSpec) DHParametersGenerator(org.bouncycastle.crypto.generators.DHParametersGenerator) AsymmetricCipherKeyPair(org.bouncycastle.crypto.AsymmetricCipherKeyPair)

Aggregations

DHParameterSpec (javax.crypto.spec.DHParameterSpec)2 DHKeyGenerationParameters (org.bouncycastle.crypto.params.DHKeyGenerationParameters)2 DHParameters (org.bouncycastle.crypto.params.DHParameters)2 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)1 KeyPair (java.security.KeyPair)1 AsymmetricCipherKeyPair (org.bouncycastle.crypto.AsymmetricCipherKeyPair)1 DHParametersGenerator (org.bouncycastle.crypto.generators.DHParametersGenerator)1 DHPrivateKeyParameters (org.bouncycastle.crypto.params.DHPrivateKeyParameters)1 DHPublicKeyParameters (org.bouncycastle.crypto.params.DHPublicKeyParameters)1