List of usage examples for org.bouncycastle.crypto.generators DESedeKeyGenerator init
public void init(KeyGenerationParameters param)
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()); }