Skip to content

Instantly share code, notes, and snippets.

@robinraju
Created May 22, 2023 13:34
Show Gist options
  • Save robinraju/ac4d133d499c48324111e2cdb4ce8ffa to your computer and use it in GitHub Desktop.
Save robinraju/ac4d133d499c48324111e2cdb4ce8ffa to your computer and use it in GitHub Desktop.
Generate MD5 hash of a string
import java.nio.charset.Charset
import java.security.MessageDigest
object MD5Hash {
def md5(value: String): String = {
val Utf8 = Charset.forName("UTF-8")
MessageDigest
.getInstance("MD5")
.digest(value.getBytes(Utf8))
.foldLeft(new StringBuilder) {
case (sb, byte) =>
sb.append("%02x".format(byte))
}
.toString()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment