Search in sources :

Example 6 with DHPrivateKeyParameters

use of org.bouncycastle.crypto.params.DHPrivateKeyParameters 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)

Example 7 with DHPrivateKeyParameters

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

the class DHBasicKeyPairGenerator method generateKeyPair.

public AsymmetricCipherKeyPair generateKeyPair() {
    DHKeyGeneratorHelper helper = DHKeyGeneratorHelper.INSTANCE;
    DHParameters dhp = param.getParameters();
    BigInteger x = helper.calculatePrivate(dhp, param.getRandom());
    BigInteger y = helper.calculatePublic(dhp, x);
    return new AsymmetricCipherKeyPair(new DHPublicKeyParameters(y, dhp), new DHPrivateKeyParameters(x, dhp));
}
Also used : DHPublicKeyParameters(org.bouncycastle.crypto.params.DHPublicKeyParameters) DHParameters(org.bouncycastle.crypto.params.DHParameters) DHPrivateKeyParameters(org.bouncycastle.crypto.params.DHPrivateKeyParameters) BigInteger(java.math.BigInteger) AsymmetricCipherKeyPair(org.bouncycastle.crypto.AsymmetricCipherKeyPair)

Example 8 with DHPrivateKeyParameters

use of org.bouncycastle.crypto.params.DHPrivateKeyParameters in project Skein3Fish by wernerd.

the class DHKeyPairGenerator method generateKeyPair.

public AsymmetricCipherKeyPair generateKeyPair() {
    DHKeyGeneratorHelper helper = DHKeyGeneratorHelper.INSTANCE;
    DHParameters dhp = param.getParameters();
    BigInteger x = helper.calculatePrivate(dhp, param.getRandom());
    BigInteger y = helper.calculatePublic(dhp, x);
    return new AsymmetricCipherKeyPair(new DHPublicKeyParameters(y, dhp), new DHPrivateKeyParameters(x, dhp));
}
Also used : DHPublicKeyParameters(org.bouncycastle.crypto.params.DHPublicKeyParameters) DHParameters(org.bouncycastle.crypto.params.DHParameters) DHPrivateKeyParameters(org.bouncycastle.crypto.params.DHPrivateKeyParameters) BigInteger(java.math.BigInteger) AsymmetricCipherKeyPair(org.bouncycastle.crypto.AsymmetricCipherKeyPair)

Aggregations

DHPrivateKeyParameters (org.bouncycastle.crypto.params.DHPrivateKeyParameters)8 DHParameters (org.bouncycastle.crypto.params.DHParameters)6 BigInteger (java.math.BigInteger)5 AsymmetricCipherKeyPair (org.bouncycastle.crypto.AsymmetricCipherKeyPair)4 DHPublicKeyParameters (org.bouncycastle.crypto.params.DHPublicKeyParameters)4 DHParameter (org.bouncycastle.asn1.pkcs.DHParameter)2 AlgorithmIdentifier (org.bouncycastle.asn1.x509.AlgorithmIdentifier)2 DSAParameter (org.bouncycastle.asn1.x509.DSAParameter)2 X962Parameters (org.bouncycastle.asn1.x9.X962Parameters)2 X9ECParameters (org.bouncycastle.asn1.x9.X9ECParameters)2 AsymmetricKeyParameter (org.bouncycastle.crypto.params.AsymmetricKeyParameter)2 DSAParameters (org.bouncycastle.crypto.params.DSAParameters)2 DSAPrivateKeyParameters (org.bouncycastle.crypto.params.DSAPrivateKeyParameters)2 ECDomainParameters (org.bouncycastle.crypto.params.ECDomainParameters)2 ECPrivateKeyParameters (org.bouncycastle.crypto.params.ECPrivateKeyParameters)2 ParametersWithRandom (org.bouncycastle.crypto.params.ParametersWithRandom)2 RSAPrivateCrtKeyParameters (org.bouncycastle.crypto.params.RSAPrivateCrtKeyParameters)2 KeyPair (java.security.KeyPair)1 DHParameterSpec (javax.crypto.spec.DHParameterSpec)1 ASN1Encodable (org.bouncycastle.asn1.ASN1Encodable)1