From 00aee6bc6ab8f64fd59191b39b1fc15235466397 Mon Sep 17 00:00:00 2001 From: czp3009 Date: Tue, 30 Jul 2019 13:06:49 +0800 Subject: [PATCH] optimize code --- rest/src/main/kotlin/com/hiczp/bilibili/rest/ktor/Cipher.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rest/src/main/kotlin/com/hiczp/bilibili/rest/ktor/Cipher.kt b/rest/src/main/kotlin/com/hiczp/bilibili/rest/ktor/Cipher.kt index 33b645b..3054a80 100644 --- a/rest/src/main/kotlin/com/hiczp/bilibili/rest/ktor/Cipher.kt +++ b/rest/src/main/kotlin/com/hiczp/bilibili/rest/ktor/Cipher.kt @@ -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)