Example usage for org.bouncycastle.crypto.params DSAKeyGenerationParameters DSAKeyGenerationParameters

List of usage examples for org.bouncycastle.crypto.params DSAKeyGenerationParameters DSAKeyGenerationParameters

Introduction

In this page you can find the example usage for org.bouncycastle.crypto.params DSAKeyGenerationParameters DSAKeyGenerationParameters.

Prototype

public DSAKeyGenerationParameters(SecureRandom random, DSAParameters params) 

Source Link

Usage

From source file:com.geoxp.oss.CryptoHelperTest.java

License:Apache License

@Test
public void testSSHSignatureBlobSign_DSA() throws Exception {
    DSAKeyPairGenerator dsakpg = new DSAKeyPairGenerator();
    DSAParametersGenerator dpg = new DSAParametersGenerator();
    dpg.init(1024, 8, new SecureRandom());
    DSAParameters dsaparams = dpg.generateParameters();
    DSAKeyGenerationParameters params = new DSAKeyGenerationParameters(new SecureRandom(), dsaparams);
    dsakpg.init(params);/*  w  ww .j a  v a2s .c o m*/

    AsymmetricCipherKeyPair kp = dsakpg.generateKeyPair();

    DSAPrivateKeyParameters privParams = (DSAPrivateKeyParameters) kp.getPrivate();
    DSAPublicKeyParameters pubParams = (DSAPublicKeyParameters) kp.getPublic();

    KeySpec ks = new DSAPrivateKeySpec(privParams.getX(), privParams.getParameters().getP(),
            privParams.getParameters().getQ(), privParams.getParameters().getG());
    PrivateKey priv = KeyFactory.getInstance("DSA").generatePrivate(ks);

    ks = new DSAPublicKeySpec(pubParams.getY(), pubParams.getParameters().getP(),
            pubParams.getParameters().getQ(), pubParams.getParameters().getG());
    PublicKey pub = KeyFactory.getInstance("DSA").generatePublic(ks);

    byte[] data = PLAINTEXT.getBytes();
    byte[] sig = CryptoHelper.sshSignatureBlobSign(data, priv);

    Assert.assertTrue(CryptoHelper.sshSignatureBlobVerify(data, sig, pub));
}

From source file:com.licel.jcardsim.crypto.DSAKeyImpl.java

License:Apache License

/**
 * Get/*from  ww w.  ja va 2 s. com*/
 * <code>DSAKeyGenerationParameters</code>
 *
 * @param rnd Secure Random Generator
 * @return parameters for use with BouncyCastle API
 */
public KeyGenerationParameters getKeyGenerationParameters(SecureRandom rnd) {
    if (isInitialized()) {
        return new DSAKeyGenerationParameters(rnd,
                new DSAParameters(p.getBigInteger(), q.getBigInteger(), g.getBigInteger()));
    }
    return getDefaultKeyGenerationParameters(size, rnd);
}

From source file:com.licel.jcardsim.crypto.DSAKeyImpl.java

License:Apache License

/**
 * Get DSA KeyGeneration Defaults Parameters
 * {@link http://docs.oracle.com/javase/6/docs/technotes/guides/security/StandardNames.html#alg}
 *
 * @param keySize key size in bits/*  w  ww.  j  av a2  s. c o m*/
 * @param rnd Secure Random Generator
 */
static KeyGenerationParameters getDefaultKeyGenerationParameters(short keySize, SecureRandom rnd) {
    BigInteger p = null;
    BigInteger q = null;
    BigInteger g = null;
    BigInteger seed = null;
    short counter = 0;
    switch (keySize) {
    case 512:
        counter = 123;
        p = new BigInteger("fca682ce8e12caba26efccf7110e526db078b05edecbcd1eb4a208f3"
                + "ae1617ae01f35b91a47e6df63413c5e12ed0899bcd132acd50d99151" + "bdc43ee737592e17", 16);
        q = new BigInteger("962eddcc369cba8ebb260ee6b6a126d9346e38c5", 16);
        g = new BigInteger("678471b27a9cf44ee91a49c5147db1a9aaf244f05a434d6486931d2d"
                + "14271b9e35030b71fd73da179069b32e2935630e1c2062354d0da20a" + "6c416e50be794ca4", 16);
        seed = new BigInteger("b869c82b35d70e1b1ff91b28e37a62ecdc34409b", 16);
        break;
    case 768:
        counter = 263;
        p = new BigInteger("e9e642599d355f37c97ffd3567120b8e25c9cd43e927b3a9670fbec5"
                + "d890141922d2c3b3ad2480093799869d1e846aab49fab0ad26d2ce6a"
                + "22219d470bce7d777d4a21fbe9c270b57f607002f3cef8393694cf45" + "ee3688c11a8c56ab127a3daf", 16);
        q = new BigInteger("9cdbd84c9f1ac2f38d0f80f42ab952e7338bf511", 16);
        g = new BigInteger("30470ad5a005fb14ce2d9dcd87e38bc7d1b1c5facbaecbe95f190aa7"
                + "a31d23c4dbbcbe06174544401a5b2c020965d8c2bd2171d366844577"
                + "1f74ba084d2029d83c1c158547f3a9f1a2715be23d51ae4d3e5a1f6a" + "7064f316933a346d3f529252", 16);
        seed = new BigInteger("77d0f8c4dad15eb8c4f2f8d6726cefd96d5bb399", 16);
        break;
    case 1024:
        counter = 92;
        p = new BigInteger("fd7f53811d75122952df4a9c2eece4e7f611b7523cef4400c31e3f80"
                + "b6512669455d402251fb593d8d58fabfc5f5ba30f6cb9b556cd7813b"
                + "801d346ff26660b76b9950a5a49f9fe8047b1022c24fbba9d7feb7c6"
                + "1bf83b57e7c6a8a6150f04fb83f6d3c51ec3023554135a169132f675"
                + "f3ae2b61d72aeff22203199dd14801c7", 16);
        q = new BigInteger("9760508f15230bccb292b982a2eb840bf0581cf5", 16);
        g = new BigInteger("f7e1a085d69b3ddecbbcab5c36b857b97994afbbfa3aea82f9574c0b"
                + "3d0782675159578ebad4594fe67107108180b449167123e84c281613"
                + "b7cf09328cc8a6e13c167a8b547c8d28e0a3ae1e2bb3a675916ea37f"
                + "0bfa213562f1fb627a01243bcca4f1bea8519089a883dfe15ae59f06"
                + "928b665e807b552564014c3bfecf492a", 16);
        seed = new BigInteger("8d5155894229d5e689ee01e6018a237e2cae64cd", 16);
        break;
    default:
        CryptoException.throwIt(CryptoException.ILLEGAL_VALUE);
        break;
    }
    return new DSAKeyGenerationParameters(rnd,
            new DSAParameters(p, q, g, new DSAValidationParameters(seed.toByteArray(), counter)));

}

From source file:dorkbox.util.crypto.CryptoDSA.java

License:Apache License

/**
 * Generates the DSA key (using RSA and SHA1)
 * <p/>/*from  ww w  .  j  a va 2s  .  c  om*/
 * Note: this is here just for keeping track of how this is done. This should NOT be used, and instead use ECC crypto.
 */
public static AsymmetricCipherKeyPair generateKeyPair(SecureRandom secureRandom, int keyLength) {
    DSAKeyPairGenerator keyGen = new DSAKeyPairGenerator();

    DSAParametersGenerator dsaParametersGenerator = new DSAParametersGenerator();
    dsaParametersGenerator.init(keyLength, 20, secureRandom);
    DSAParameters generateParameters = dsaParametersGenerator.generateParameters();

    DSAKeyGenerationParameters params = new DSAKeyGenerationParameters(secureRandom, generateParameters);
    keyGen.init(params);
    return keyGen.generateKeyPair();
}