Skip to content

Instantly share code, notes, and snippets.

@mutkuensert
Created June 4, 2024 15:19
Show Gist options
  • Save mutkuensert/e26983569f2a140dfe1b5fb62eeefad6 to your computer and use it in GitHub Desktop.
Save mutkuensert/e26983569f2a140dfe1b5fb62eeefad6 to your computer and use it in GitHub Desktop.
Certificate public key to sha256 pin converter
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