(char[] masterPassword, byte[] salt)
| 98 | } |
| 99 | |
| 100 | private static SecretKey deriveKey(char[] masterPassword, byte[] salt) throws Exception { |
| 101 | KeySpec spec = new PBEKeySpec(masterPassword, salt, ITERATIONS, KEY_LENGTH); |
| 102 | SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256"); |
| 103 | byte[] keyBytes = factory.generateSecret(spec).getEncoded(); |
| 104 | return new SecretKeySpec(keyBytes, SECRET_KEY_ALGORITHM); |
| 105 | } |
| 106 | |
| 107 | private String encrypt(String masterPassword, String password) { |
| 108 | try { |