Created
June 4, 2024 15:19
-
-
Save mutkuensert/e26983569f2a140dfe1b5fb62eeefad6 to your computer and use it in GitHub Desktop.
Certificate public key to sha256 pin converter
This file contains 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 SslUtils { | |
fun getBase64UrlEncodedSha256(publicKey: String): String { | |
return Base64.getUrlEncoder().encodeToString(publicKey.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