Skip to content

Instantly share code, notes, and snippets.

@nilsmagnus
Created May 12, 2020 04:53
Show Gist options
  • Save nilsmagnus/750432977ff3c938026ed1cd7323bba8 to your computer and use it in GitHub Desktop.
Save nilsmagnus/750432977ff3c938026ed1cd7323bba8 to your computer and use it in GitHub Desktop.
Get public key from android keystore
import java.security.KeyStore
import arrow.core.Option
const val SIGN_CERT_ALIAS = "SIGN"
fun getPublicSigningKey(): Option<PublicKey> =
runCatching {
val ks: KeyStore = KeyStore.getInstance("AndroidKeyStore").apply {
load(null)
}
ks.getCertificate(SIGN_CERT_ALIAS).publicKey
}.fold({
Option.just(it)
}, {
Option.empty()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment