Example usage for org.bouncycastle.crypto KeyGenerationParameters KeyGenerationParameters

List of usage examples for org.bouncycastle.crypto KeyGenerationParameters KeyGenerationParameters

Introduction

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

Prototype

public KeyGenerationParameters(SecureRandom random, int strength) 

Source Link

Document

initialise the generator with a source of randomness and a strength (in bits).

Usage

From source file:com.distrimind.util.crypto.NewHopeKeyAgreementClient.java

License:Open Source License

private byte[] getDataPhase1() {
    valid = false;/*from www .  j  av  a  2 s  . c  om*/
    //init key pair
    NHKeyPairGenerator keyPairEngine = new NHKeyPairGenerator();

    keyPairEngine.init(new KeyGenerationParameters(randomForKeys, 1024));
    AsymmetricCipherKeyPair pair = keyPairEngine.generateKeyPair();
    NHPublicKeyParameters pub = (NHPublicKeyParameters) pair.getPublic();
    priv = (NHPrivateKeyParameters) pair.getPrivate();

    byte[] res = pub.getPubData();
    valid = true;
    return res;
}

From source file:com.oneops.cms.crypto.CmsCryptoDES.java

License:Apache License

/**
 * Generate des key.//from w w  w  . j a  va 2s. co  m
 *
 * @param file the file
 * @throws java.io.IOException Signals that an I/O exception has occurred.
 */
public static void generateDESKey(String file) throws IOException {
    DESedeKeyGenerator kg = new DESedeKeyGenerator();
    KeyGenerationParameters kgp = new KeyGenerationParameters(new SecureRandom(),
            DESedeParameters.DES_EDE_KEY_LENGTH * 8);
    kg.init(kgp);
    byte[] key = kg.generateKey();
    BufferedOutputStream keystream = new BufferedOutputStream(new FileOutputStream(file));
    byte[] keyhex = Hex.encode(key);
    keystream.write(keyhex, 0, keyhex.length);
    keystream.flush();
    keystream.close();
}

From source file:com.thoughtworks.go.security.CipherProvider.java

License:Apache License

private byte[] generateKey() {
    SecureRandom random = new SecureRandom();
    random.setSeed("go-server".getBytes());
    KeyGenerationParameters generationParameters = new KeyGenerationParameters(random,
            DESParameters.DES_KEY_LENGTH * 8);
    DESKeyGenerator generator = new DESKeyGenerator();
    generator.init(generationParameters);
    return Hex.encode(generator.generateKey());
}

From source file:com.thoughtworks.go.security.DESCipherProvider.java

License:Apache License

private byte[] generateKey() {
    SecureRandom random = new SecureRandom();
    random.setSeed(UUID.randomUUID().toString().getBytes());
    KeyGenerationParameters generationParameters = new KeyGenerationParameters(random,
            DESParameters.DES_KEY_LENGTH * 8);
    DESKeyGenerator generator = new DESKeyGenerator();
    generator.init(generationParameters);
    return generator.generateKey();
}

From source file:com.zotoh.crypto.BCOfuscator.java

License:Open Source License

@SuppressWarnings("unused")
private static void genkey() throws Exception {
    // create 2 things for the generation of a key
    // 1. random gen
    // 2. key length in bits
    SecureRandom rnd = Crypto.getInstance().getSecureRandom();
    // DESede key must be 192 or 128 bits long only
    int strength = DESedeParameters.DES_EDE_KEY_LENGTH * 8;

    KeyGenerationParameters kgp = new KeyGenerationParameters(rnd, strength);
    DESedeKeyGenerator kg = new DESedeKeyGenerator();
    kg.init(kgp);/* w w w .  j ava2  s  . c om*/

    Base64.encodeBase64(kg.generateKey());
}

From source file:ovh.tgrhavoc.aibot.protocol.EncryptionUtil.java

License:Open Source License

public static SecretKey generateSecretKey() {
    CipherKeyGenerator generator = new CipherKeyGenerator();
    generator.init(new KeyGenerationParameters(new SecureRandom(), 128));
    return new SecretKeySpec(generator.generateKey(), "AES");
}