I want to convert my c# codes to java with PBKDF2 hashing and with the same result(no real product, just test).
C#:
static string Pbkdf2Hashing(string password)
{
byte[] salt = new byte[128 / 8];
string hashed = Convert.ToBase64String(KeyDerivation.Pbkdf2(
password: password,
salt: salt,
prf: KeyDerivationPrf.HMACSHA1,
iterationCount: 10000,
numBytesRequested: 256 / 8));
return hashed;
}
The result:
List item
oudaCubzWVIMjTxaQh1KT85fn+p2KjQRdBDXpiS8AUA=
Java:
static String Pbkdf2Hashing(String password) throws Exception {
byte[] salt = new byte[128 / 8];
int iterations = 10000;
int derivedKeyLength = 256;
KeySpec spec = new PBEKeySpec(password.toCharArray(), salt, iterations, derivedKeyLength);
SecretKeyFactory f = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256");
byte[] result = f.generateSecret(spec).getEncoded();
return Base64.getEncoder().encodeToString(result);
}
The result:
dxtD2eQ/4Sj5pGnPqCTiuL6jns5apO1OHkTaJC9DTzw=