Here you can find the source of generateKey()
public static SecretKey generateKey() throws NoSuchAlgorithmException
//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 ALGO = "AES"; private static final int KEYSZ = 256; public static SecretKey generateKey() throws NoSuchAlgorithmException { KeyGenerator keyGenerator = KeyGenerator.getInstance(ALGO); keyGenerator.init(KEYSZ);//from ww w . ja v a2 s . co m SecretKey key = keyGenerator.generateKey(); return key; } }