Here you can find the source of generateKey(char[] password)
public static Key generateKey(char[] password) throws NoSuchAlgorithmException, InvalidKeySpecException
//package com.java2s; //License from project: Open Source License import java.security.Key; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; import java.security.spec.InvalidKeySpecException; import java.security.spec.KeySpec; import javax.crypto.SecretKey; import javax.crypto.SecretKeyFactory; import javax.crypto.spec.PBEKeySpec; import javax.crypto.spec.SecretKeySpec; public class Main { public static Key generateKey(char[] password) throws NoSuchAlgorithmException, InvalidKeySpecException { return generateKey(password, generateSalt(128)); }// w w w . j a va 2 s .c o m public static Key generateKey(char[] password, byte[] salt) throws NoSuchAlgorithmException, InvalidKeySpecException { SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256"); KeySpec spec = new PBEKeySpec(password, salt, 65536, 256); SecretKey tmp = factory.generateSecret(spec); SecretKey secret = new SecretKeySpec(tmp.getEncoded(), "AES"); return secret; } public static byte[] generateSalt(int length) { byte[] salt = new byte[length]; SecureRandom rnd = null; try { rnd = SecureRandom.getInstanceStrong(); } catch (NoSuchAlgorithmException e) { rnd = new SecureRandom(); } rnd.nextBytes(salt); return salt; } }