· 7 years ago · Nov 22, 2018, 03:30 PM
1public static void main(String[] args) throws Exception {
2 char[] password = "Hello, World!!".toCharArray();
3 byte[] salt = new byte[] {1, 2, 3, 4, 5, 6, 7, 8};
4 SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
5 KeySpec spec = new PBEKeySpec(password, salt, 65536, 128); // ã‚ーã¯128Bit
6 SecretKey tmp = factory.generateSecret(spec);
7 byte[] digest = tmp.getEncoded();
8 for (byte d : digest) {
9 System.out.print(String.format("%02x", d));
10 }
11 System.out.println();
12 // 2adfe63d125ae48eb056893dd18bc643
13}