private static SecretKey generateSymmetricKey() throws Exception { KeyGenerator generator = KeyGenerator.getInstance(KEY_ALGORITHM); SecureRandom random = new SecureRandom(); generator.init(KEY_LENGTH_BITS, random); logger.debug("Generate Key"); return generator.generateKey(); // return new SecretKeySpec(Hex.decodeHex("cb024600dce7148b8ddc5d6c111fbd85".toCharArray()), // KEY_ALGORITHM); }
public void generate_new_aes_key() { try { KeyGenerator localKeyGenerator = KeyGenerator.getInstance("AES"); localKeyGenerator.init(128, SecureRandom.getInstance("SHA1PRNG")); // aes_key = Base64.encodeBase64String(localKeyGenerator.generateKey().getEncoded()); aes_key = new String(Base64.encode(localKeyGenerator.generateKey().getEncoded(), Base64.DEFAULT)); } catch (NoSuchAlgorithmException localNoSuchAlgorithmException) { System.out.println(localNoSuchAlgorithmException); } return; }