Hi,
I am using bouncy castle API as below.
iterations = 10000 password = abcdefghi salt = zyxwvutsrqpo
>Need return value as 8 bytes.
public byte[] getEncodedHash(String password, String salt, int iterations) throws UnsupportedEncodingException {
PKCS5S2ParametersGenerator gen = new PKCS5S2ParametersGenerator(newSHA256Digest());
try {
gen.init(password.getBytes("UTF-8"), salt.getBytes(), iterations);
} catch (UnsupportedEncodingException ex) {
throw ex;
}
byte[] dk = ((KeyParameter) gen.generateDerivedParameters(64)).getKey();
return dk;
}
Calling above function as below.
==================================
byte[] hashbyte = hasher.getEncodedHash(pass, salt, iterations);
System.out.println(Arrays.toString(hashbyte));
Output as below:
==================
[44, -6, -117, 7, -30, -68, 4, -9]
>Why am I getting negative bytes and is there anyway to get only positive bytes?
When I have checked with client which they are using Python script and they always get positive integers (I need to develop in Java using bouncy castle). Surprising is, whatever positive numbers I have, they match exactly on their side at respective index (output from Python script).
Appreciate your valuable input on this.