· 8 years ago · Feb 05, 2018, 09:42 PM
1int iterations = 250000;
2String password = "password";
3String salt = "salt";
4
5SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256");
6char[] passwordChars = password.toCharArray();
7KeySpec spec = new PBEKeySpec(passwordChars, salt.getBytes(), iterations, 256);
8SecretKey key = factory.generateSecret(spec);
9
10byte[] passwordHash = key.getEncoded();
11
12SecretKey secret = new SecretKeySpec(key.getEncoded(), "AES");