Java tutorial
//package com.java2s; //License from project: Apache License import java.security.NoSuchAlgorithmException; import javax.crypto.KeyGenerator; import javax.crypto.SecretKey; public class Main { private static final String KEY_ALGORITHM = "AES"; public static byte[] initKey(int size) throws NoSuchAlgorithmException { KeyGenerator kg = KeyGenerator.getInstance(KEY_ALGORITHM); kg.init(size); SecretKey secretKey = kg.generateKey(); return secretKey.getEncoded(); } }