The problem is the last line. If you return digest.toString()
, you are returning the String representation of your byte array (which looks something like [B@12345678]
). If you really want to build a String
from the byte[]
, I would strongly suggest you Base64 encode your array:
return new String(Base64.encode(digest));
You'll find Base64 as part of Java8, if you're using something older, you'll find one in Apache codec, Spring utils, etc....