1

I have the following Scala function:

import java.security.MessageDigest
def md5(s: String) = MessageDigest.getInstance("MD5").digest(s.getBytes).toString()

When I encrypt the same string, I always get different results, what could be the problem? There are no new lines or spaces at the end of the input strings and all of them have the same length.

4

1 回答 1

0

你要:

def md5(s: String) = {
    MessageDigest.getInstance("MD5").digest(s.getBytes).map("%02x".format(_)).mkString
}
于 2016-06-03T12:58:29.640 回答