The community reviewed whether to reopen this question 1 year ago and left it closed:
Original close reason(s) were not resolved
Possible Duplicate:
开发者_如何学JAVAGenerate MD5 hash in Java
Hi,
I want to compute the MD5 hash of a string in my scala code. Is there any scala or java library i can use to do this quickly, apart from the regular java.security.MessageDigest way ?
Please Help Thanks
You may be reinventing a very tiny wheel here, but just write a function to do what you want: take a string, use MessageDigest, and return whatever (hex string, byte array) you need.
import java.security.MessageDigest
def md5(s: String) = {
MessageDigest.getInstance("MD5").digest(s.getBytes)
}
md5("Hello")
P.S. I don't write Scala, but this works and it's left as an exercise to the reader to turn it into anything other than an Array[Byte]
精彩评论