I would like to fetch the RSA public key from an HTTPS server in my Android app.
I don't care wether it is valid or not.
Ideally; I would like to be able to extract infos about the whole certificate chain.
How to achieve this?
It's actually trivial.
val url = URL(BASE_WEB_ENDPOINT_PRIMARY)
val connection: HttpsURLConnection = url.openConnection() as HttpsURLConnection
connection.connect()
connection.serverCertificates.forEach {
it.publicKey // <== the public key
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.