I’m storing the user password on the db as a sha1 hash.
Unfortunately I’m getting strange answers.
I’m storing the string as this:
MessageDigest cript = MessageDigest.getInstance("SHA-1");
cript.reset();
cript.update(userPass.getBytes("utf8"));
this.password = new String(cript.digest());
I wanted something like this –>
aff –> “0c05aa56405c447e6678b7f3127febde5c3a9238”
rather than
aff –> �V@\D~fx����:�8
This is happening because cript.digest() returns a byte array, which you’re trying to print out as a character String. You want to convert it to a printable Hex String.
Easy solution: Use Apache’s commons-codec library: