Example usage for org.bouncycastle.crypto.params DESedeParameters DES_EDE_KEY_LENGTH

List of usage examples for org.bouncycastle.crypto.params DESedeParameters DES_EDE_KEY_LENGTH

Introduction

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

Prototype

int DES_EDE_KEY_LENGTH

To view the source code for org.bouncycastle.crypto.params DESedeParameters DES_EDE_KEY_LENGTH.

Click Source Link

Usage

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

License:Apache License

/**
 * Generate des key.//from   w w w.ja  v a2s . 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.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 w  ww.  j a v a  2 s .co m

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