Android: String to MD5

Apr 8, 2019
fun String.toMD5(): String {    // toByteArray: default is Charsets.UTF_8 - https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/to-byte-array.html    val bytes = MessageDigest.getInstance("MD5").digest(this.toByteArray())    return bytes.toHex()}fun ByteArray.toHex(): String {    return joinToString("") { "%02x".format(it) }}
val hash = "abc".toMD5() // "900150983cd24fb0d6963f7d28e17f72"

NOTE: MD5 Test Suite

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.