|
@@ -31,11 +31,22 @@ public class PBKDF2 extends ReactContextBaseJavaModule {
|
|
|
}
|
|
|
return new String(hexChars);
|
|
|
}
|
|
|
+
|
|
|
+ public static byte[] hexStringToByteArray(String s) {
|
|
|
+ int len = s.length();
|
|
|
+ byte[] data = new byte[len / 2];
|
|
|
+ for (int i = 0; i < len; i += 2) {
|
|
|
+ data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4)
|
|
|
+ + Character.digit(s.charAt(i+1), 16));
|
|
|
+ }
|
|
|
+ return data;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
private static String derivationKey(String pwd, String salt, Integer cost, Integer length)
|
|
|
throws NoSuchAlgorithmException, InvalidKeySpecException {
|
|
|
PKCS5S2ParametersGenerator gen = new PKCS5S2ParametersGenerator(new SHA512Digest());
|
|
|
- gen.init(pwd.getBytes(StandardCharsets.UTF_8), salt.getBytes(StandardCharsets.UTF_8), cost);
|
|
|
+ gen.init(hexStringToByteArray(pwd), hexStringToByteArray(salt), cost);
|
|
|
byte[] key = ((KeyParameter) gen.generateDerivedParameters(length)).getKey();
|
|
|
return bytesToHex(key);
|
|
|
}
|