Search in sources :

Example 1 with AsymmetricCipherKeyPair

use of org.bouncycastle.crypto.AsymmetricCipherKeyPair in project robovm by robovm.

the class ECKeyPairGenerator method generateKeyPair.

/**
     * Given the domain parameters this routine generates an EC key
     * pair in accordance with X9.62 section 5.2.1 pages 26, 27.
     */
public AsymmetricCipherKeyPair generateKeyPair() {
    BigInteger n = params.getN();
    int nBitLength = n.bitLength();
    BigInteger d;
    do {
        d = new BigInteger(nBitLength, random);
    } while (d.equals(ZERO) || (d.compareTo(n) >= 0));
    ECPoint Q = params.getG().multiply(d);
    return new AsymmetricCipherKeyPair(new ECPublicKeyParameters(Q, params), new ECPrivateKeyParameters(d, params));
}
Also used : ECPrivateKeyParameters(org.bouncycastle.crypto.params.ECPrivateKeyParameters) BigInteger(java.math.BigInteger) ECPoint(org.bouncycastle.math.ec.ECPoint) ECPublicKeyParameters(org.bouncycastle.crypto.params.ECPublicKeyParameters) ECPoint(org.bouncycastle.math.ec.ECPoint) AsymmetricCipherKeyPair(org.bouncycastle.crypto.AsymmetricCipherKeyPair)

Example 2 with AsymmetricCipherKeyPair

use of org.bouncycastle.crypto.AsymmetricCipherKeyPair in project XobotOS by xamarin.

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 3 with AsymmetricCipherKeyPair

use of org.bouncycastle.crypto.AsymmetricCipherKeyPair in project XobotOS by xamarin.

the class DSAKeyPairGenerator method generateKeyPair.

public AsymmetricCipherKeyPair generateKeyPair() {
    DSAParameters dsaParams = param.getParameters();
    BigInteger x = generatePrivateKey(dsaParams.getQ(), param.getRandom());
    BigInteger y = calculatePublicKey(dsaParams.getP(), dsaParams.getG(), x);
    return new AsymmetricCipherKeyPair(new DSAPublicKeyParameters(y, dsaParams), new DSAPrivateKeyParameters(x, dsaParams));
}
Also used : DSAPublicKeyParameters(org.bouncycastle.crypto.params.DSAPublicKeyParameters) DSAPrivateKeyParameters(org.bouncycastle.crypto.params.DSAPrivateKeyParameters) BigInteger(java.math.BigInteger) DSAParameters(org.bouncycastle.crypto.params.DSAParameters) AsymmetricCipherKeyPair(org.bouncycastle.crypto.AsymmetricCipherKeyPair)

Example 4 with AsymmetricCipherKeyPair

use of org.bouncycastle.crypto.AsymmetricCipherKeyPair in project Skein3Fish by wernerd.

the class ECKeyPairGenerator method generateKeyPair.

/**
     * Given the domain parameters this routine generates an EC key
     * pair in accordance with X9.62 section 5.2.1 pages 26, 27.
     */
public AsymmetricCipherKeyPair generateKeyPair() {
    BigInteger n = params.getN();
    int nBitLength = n.bitLength();
    BigInteger d;
    do {
        d = new BigInteger(nBitLength, random);
    } while (d.equals(ZERO) || (d.compareTo(n) >= 0));
    ECPoint Q = params.getG().multiply(d);
    return new AsymmetricCipherKeyPair(new ECPublicKeyParameters(Q, params), new ECPrivateKeyParameters(d, params));
}
Also used : ECPrivateKeyParameters(org.bouncycastle.crypto.params.ECPrivateKeyParameters) BigInteger(java.math.BigInteger) ECPoint(org.bouncycastle.math.ec.ECPoint) ECPublicKeyParameters(org.bouncycastle.crypto.params.ECPublicKeyParameters) ECPoint(org.bouncycastle.math.ec.ECPoint) AsymmetricCipherKeyPair(org.bouncycastle.crypto.AsymmetricCipherKeyPair)

Example 5 with AsymmetricCipherKeyPair

use of org.bouncycastle.crypto.AsymmetricCipherKeyPair in project robovm by robovm.

the class KeyPairGeneratorSpi method generateKeyPair.

public KeyPair generateKeyPair() {
    if (!initialised) {
        DSAParametersGenerator pGen = new DSAParametersGenerator();
        pGen.init(strength, certainty, random);
        param = new DSAKeyGenerationParameters(random, pGen.generateParameters());
        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));
}
Also used : DSAParametersGenerator(org.bouncycastle.crypto.generators.DSAParametersGenerator) DSAPublicKeyParameters(org.bouncycastle.crypto.params.DSAPublicKeyParameters) KeyPair(java.security.KeyPair) AsymmetricCipherKeyPair(org.bouncycastle.crypto.AsymmetricCipherKeyPair) DSAKeyGenerationParameters(org.bouncycastle.crypto.params.DSAKeyGenerationParameters) DSAPrivateKeyParameters(org.bouncycastle.crypto.params.DSAPrivateKeyParameters) AsymmetricCipherKeyPair(org.bouncycastle.crypto.AsymmetricCipherKeyPair)

Aggregations

AsymmetricCipherKeyPair (org.bouncycastle.crypto.AsymmetricCipherKeyPair)13 BigInteger (java.math.BigInteger)10 DHParameters (org.bouncycastle.crypto.params.DHParameters)4 DHPrivateKeyParameters (org.bouncycastle.crypto.params.DHPrivateKeyParameters)4 DHPublicKeyParameters (org.bouncycastle.crypto.params.DHPublicKeyParameters)4 KeyPair (java.security.KeyPair)3 DSAPrivateKeyParameters (org.bouncycastle.crypto.params.DSAPrivateKeyParameters)3 DSAPublicKeyParameters (org.bouncycastle.crypto.params.DSAPublicKeyParameters)3 ECPrivateKeyParameters (org.bouncycastle.crypto.params.ECPrivateKeyParameters)3 ECPublicKeyParameters (org.bouncycastle.crypto.params.ECPublicKeyParameters)3 RSAKeyParameters (org.bouncycastle.crypto.params.RSAKeyParameters)3 RSAPrivateCrtKeyParameters (org.bouncycastle.crypto.params.RSAPrivateCrtKeyParameters)3 ECPoint (org.bouncycastle.math.ec.ECPoint)3 DSAParameters (org.bouncycastle.crypto.params.DSAParameters)2 DHParameterSpec (javax.crypto.spec.DHParameterSpec)1 DHParametersGenerator (org.bouncycastle.crypto.generators.DHParametersGenerator)1 DSAParametersGenerator (org.bouncycastle.crypto.generators.DSAParametersGenerator)1 DHKeyGenerationParameters (org.bouncycastle.crypto.params.DHKeyGenerationParameters)1 DSAKeyGenerationParameters (org.bouncycastle.crypto.params.DSAKeyGenerationParameters)1