Last active
December 27, 2024 06:54
-
-
Save mutkuensert/2df49418a97a0511e0b5b2fe39066729 to your computer and use it in GitHub Desktop.
HexCodeUtils
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
object HexToBase64 { | |
fun encode(hex: String): String { | |
return Base64.getUrlEncoder().encodeToString(hex.decodeHex()) | |
} | |
private fun String.decodeHex(): ByteArray { | |
check(length % 2 == 0) { "Must have an even length" } | |
return chunked(2) | |
.map { it.toInt(16).toByte() } | |
.toByteArray() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment