Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SHA256 fingerprint from X509Certificate

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

X509Certificate get SHA256

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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("%02x", it) }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading