CertificateStore

X.509 certificates and identities (a certificate chain plus its private key), stored with the platform's native protection. PKCS#12 identities keep their private key in native key storage; certificate chains and the alias index are kept in the platform's secure secret storage.

Stores are isolated by service/account namespace like the other stores, and imports replace any existing entry with the same alias.

val certificates = CertificateStore.forCurrentPlatform(serviceName = "my-app", accountName = "user-123")
val identity = certificates.importPkcs12("client", pkcs12Bytes, passphrase)
certificates.importCertificate("pinned-ca", caDer)
val chain: List<ByteArray>? = certificates.info("client")?.certificateChainDer

Types

Link copied to clipboard
object Companion

Platform-specific factories for creating an application-scoped certificate store.

Functions

Link copied to clipboard
abstract fun aliases(): List<String>

Returns every alias in this store, sorted.

Link copied to clipboard
abstract fun clear()

Deletes every entry in this store's service/account namespace, including private keys.

Link copied to clipboard
abstract fun delete(alias: String)

Deletes the entry under alias, including any private key. Deleting a missing entry succeeds silently as long as the backend itself is available.

Link copied to clipboard
abstract fun importCertificate(alias: String, certificateDer: ByteArray): CertificateInfo

Imports a single DER-encoded X.509 certificate under alias, replacing any existing entry.

Link copied to clipboard
abstract fun importPkcs12(alias: String, pkcs12: ByteArray, passphrase: CharArray): CertificateInfo

Imports the single identity in pkcs12 under alias, replacing any existing entry.

Link copied to clipboard
abstract fun info(alias: String): CertificateInfo?

Returns the entry stored under alias.

Link copied to clipboard

Returns the Android Keystore entry of the identity stored under alias, for use with Signature, KeyManagerFactory, or an SSLContext. The private key stays inside Android Keystore.

Returns the private key and certificate chain of the identity stored under alias, for use with Signature, KeyManagerFactory, or an SSLContext.

Link copied to clipboard
fun CertificateStore.secIdentity(alias: String): SecIdentityRef?

Returns the keychain identity stored under alias, for use with URLSession client authentication or SecIdentityCopyPrivateKey. The reference is retained: release it with CFRelease when done.