Skip to content

Instantly share code, notes, and snippets.

@mutkuensert
Last active December 27, 2024 06:54
Show Gist options
  • Save mutkuensert/2df49418a97a0511e0b5b2fe39066729 to your computer and use it in GitHub Desktop.
Save mutkuensert/2df49418a97a0511e0b5b2fe39066729 to your computer and use it in GitHub Desktop.
HexCodeUtils
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