Example usage for org.bouncycastle.crypto.generators DESedeKeyGenerator generateKey

List of usage examples for org.bouncycastle.crypto.generators DESedeKeyGenerator generateKey

Introduction

In this page you can find the example usage for org.bouncycastle.crypto.generators DESedeKeyGenerator generateKey.

Prototype

public byte[] generateKey() 

Source Link

Usage

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

License:Apache License

/**
 * Generate des key./*  w  w w .j  a  v  a  2 s  .c om*/
 *
 * @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.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);//from  www.j  a  va2  s . co  m

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