Home > Software design >  SHA256 fingerprint from X509Certificate
SHA256 fingerprint from X509Certificate

Time:12-20

How to decode the SHA256 fingerprint from X509Certificate in Kotlin without third library usage in hex.

X509Certificate get SHA256

CodePudding user response:

you can use the MessageDigest from Java Security API

import java.security.MessageDigest
import java.security.cert.X509Certificate

fun decodeSHA256Fingerprint(cert: X509Certificate): String {
    val sha256 = MessageDigest.getInstance("SHA-256")
    val fingerprint = sha256.digest(cert.encoded)
    return fingerprint.joinToString(separator = "") { String.format("x", it) }
}
  • Related