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

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

Introduction

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

Prototype

public void init(KeyGenerationParameters param) 

Source Link

Document

initialise the key generator - if strength is set to zero the key generated will be 192 bits in size, otherwise strength can be 128 or 192 (or 112 or 168 if you don't count parity bits), depending on whether you wish to do 2-key or 3-key triple DES.

Usage

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

License:Apache License

/**
 * Generate des key.//from ww w  .  ja  va 2s .  c o 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);

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