List of usage examples for javax.crypto KeyGenerator getInstance
public static final KeyGenerator getInstance(String algorithm) throws NoSuchAlgorithmException
From source file:Main.java
private static byte[] iv() { byte[] iv = null; try {//from ww w. j a va2 s .c om KeyGenerator kgen = KeyGenerator.getInstance("AES"); kgen.init(128); SecretKey skey = kgen.generateKey(); iv = skey.getEncoded(); } catch (Exception e) { e.printStackTrace(); } return iv; }
From source file:Main.java
private static byte[] getRawKey(byte[] paramArrayOfByte) throws Exception { KeyGenerator localKeyGenerator = KeyGenerator.getInstance("AES"); SecureRandom localSecureRandom = SecureRandom.getInstance("SHA1PRNG", "Crypto"); localSecureRandom.setSeed(paramArrayOfByte); localKeyGenerator.init(128, localSecureRandom); return localKeyGenerator.generateKey().getEncoded(); }
From source file:Main.java
private static byte[] getRawKey(byte[] seed) throws Exception { KeyGenerator kgen = KeyGenerator.getInstance("AES"); SecureRandom sr = SecureRandom.getInstance("SHA1PRNG", "Crypto"); sr.setSeed(seed);/*w ww . j ava2 s. c o m*/ kgen.init(256, sr); // 192 and 256 bits may not be available SecretKey skey = kgen.generateKey(); byte[] raw = skey.getEncoded(); return raw; }
From source file:Main.java
private static byte[] getRawKey(byte[] seed) throws Exception { KeyGenerator kgen = KeyGenerator.getInstance("AES"); SecureRandom sr = SecureRandom.getInstance("SHA1PRNG", "Crypto"); sr.setSeed(seed);/*from w w w. j av a 2 s . c om*/ kgen.init(128, sr); SecretKey skey = kgen.generateKey(); byte[] raw = skey.getEncoded(); return raw; }
From source file:Main.java
private static byte[] getRawKey(byte[] seed) throws Exception { KeyGenerator kgen = KeyGenerator.getInstance("AES"); SecureRandom sr = SecureRandom.getInstance("SHA1PRNG", "Crypto"); sr.setSeed(seed);// w w w.j a va 2 s. c o m kgen.init(128, sr); SecretKey sKey = kgen.generateKey(); byte[] raw = sKey.getEncoded(); return raw; }
From source file:Main.java
private static byte[] getRawKey(byte[] seed) throws Exception { KeyGenerator kgen = KeyGenerator.getInstance("AES"); SecureRandom sr = SecureRandom.getInstance("SHA1PRNG"); sr.setSeed(seed);// ww w . j a v a 2 s . c o m kgen.init(128, sr); SecretKey sKey = kgen.generateKey(); byte[] raw = sKey.getEncoded(); return raw; }
From source file:Main.java
public static byte[] initKey() throws NoSuchAlgorithmException { KeyGenerator keyGen = KeyGenerator.getInstance("AES"); keyGen.init(256); //192 256 SecretKey secretKey = keyGen.generateKey(); return secretKey.getEncoded(); }
From source file:Main.java
public static SecretKey generateAesKey() { try {// w w w . ja v a 2 s . c o m KeyGenerator kg = KeyGenerator.getInstance("AES"); kg.init(KEY_LENGTH_AES); SecretKey key = kg.generateKey(); return key; } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } }
From source file:Main.java
private static Key newDesInstance(String strKey) { Key key = null;/*from w w w . j a va2 s . co m*/ try { KeyGenerator keyGenerator = KeyGenerator.getInstance("DES"); keyGenerator.init(new SecureRandom(strKey.getBytes())); key = keyGenerator.generateKey(); keyGenerator = null; } catch (Exception e) { e.printStackTrace(); } return key; }
From source file:Main.java
/** * do not work/* ww w . j a v a 2 s . c o m*/ */ private static byte[] getRawKey(byte[] seed) throws Exception { KeyGenerator keyGenerator = KeyGenerator.getInstance("AES"); keyGenerator.init(128, new SecureRandom(seed)); // 192 and 256 bits may not be available return keyGenerator.generateKey().getEncoded(); }