Here you can find the source of generateKey()
public static SecretKey generateKey() throws NoSuchAlgorithmException
//package com.java2s; //License from project: Open Source License import javax.crypto.*; import java.security.NoSuchAlgorithmException; public class Main { private static final int AES_KEYLENGTH = 128; /**//w w w .j a v a2s . c om * Step 1. Generate an AES key using KeyGenerator Initialize the * keysize to 128 bits (16 bytes) */ public static SecretKey generateKey() throws NoSuchAlgorithmException { KeyGenerator keyGenerator = KeyGenerator.getInstance("AES"); keyGenerator.init(AES_KEYLENGTH); return keyGenerator.generateKey(); } }