Last active
February 22, 2022 07:59
-
-
Save robinraju/100854f6957ca208eee9c886dfd5d1c8 to your computer and use it in GitHub Desktop.
MD5 hash using Scala
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 | |
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(byte.formatted("%02x")) | |
} | |
.toString() | |
} | |
// SclaJS implementation | |
def md5(value: String): String = | |
scala.scalajs.js.Dynamic.global.CryptoJS.MD5(value).toString |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment