I am producing a hashed value of a password with salt.My code:
`String psw="hello";
String tobehashed="";
tobehashed=salt+psw;
MessageDigest md = MessageDigest.getInstance("SHA-256");
byte[] digest = md.digest(tobehashed.getBytes());
System.out.println("Digest:"+digest);`
I have produced salt by providing seed as current time in milliseconds,I have no issues with salt(I m getting random values) but irrespective of salt I am getting same hash value..
Actually the purpose of salt is to get different hash values..
This is my output;
Random nubr:-2098016229(this keeps changing)
Digest:[B@ca0b6(this remains same)
Waht is the solution??
You are printing out the result of
digest.toString(), which in the case of a byte array does not convert the bytes to meaningful output. It just prints[B(which is the code for byte array),@, and then a hex address. You will see this output often as you get more experience with Java.You will need to use a loop to iterate through the bytes in the digest and print them individually.