optimize code

This commit is contained in:
czp3009
2019-07-30 13:06:49 +08:00
parent 3892b9760d
commit 00aee6bc6a

View File

@@ -10,13 +10,13 @@ import javax.crypto.Cipher
private val hexTable = "0123456789abcdef".toCharArray()
//optimized md5
internal fun String.md5() = StringBuilder(32).apply {
internal fun String.md5() = buildString(32) {
MessageDigest.getInstance("MD5").digest(toByteArray()).forEach {
val value = it.toInt() and 0xFF
append(hexTable[value ushr 4])
append(hexTable[value and 0x0F])
}
}.toString()
}
internal fun String.base64() = Base64.getDecoder().decode(this)