Skip to content

Instantly share code, notes, and snippets.

@dlimpid
Created July 7, 2017 09:34
Show Gist options
  • Save dlimpid/68761108b49b7c1ddb84250dfac78495 to your computer and use it in GitHub Desktop.
Save dlimpid/68761108b49b7c1ddb84250dfac78495 to your computer and use it in GitHub Desktop.
Get MD5 hash of the string (of length 32, with leading zeros) in Kotlin
import java.math.BigInteger
import java.security.MessageDigest
fun String.md5(): String {
val md = MessageDigest.getInstance("MD5")
return BigInteger(1, md.digest(toByteArray())).toString(16).padStart(32, '0')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment