Created
May 22, 2023 13:34
-
-
Save robinraju/ac4d133d499c48324111e2cdb4ce8ffa to your computer and use it in GitHub Desktop.
Generate MD5 hash of a string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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