forCurrentPlatform

fun CertificateStore.Companion.forCurrentPlatform(context: Context, serviceName: String, accountName: String = serviceName): CertificateStore(source)

Creates a certificate store isolated by serviceName and accountName. Private keys of imported identities are moved into Android Keystore, where they cannot be exported; certificate chains and the alias index are kept in the same encrypted, non-backed-up files as CredentialKeychain, under a separate namespace.

context is retained only as Context.getApplicationContext.

val certificates = CertificateStore.forCurrentPlatform(
context = applicationContext,
serviceName = "my-app",
accountName = "user-123",
)

Parameters

context

any Android Context; only its application context is retained.

serviceName

identifies the calling application or integration; must be nonblank and free of NUL/CR/LF.

accountName

identifies the certificate owner; defaults to serviceName. Same validity rules as serviceName.

Throws

if serviceName or accountName is blank or contains NUL, CR, or LF.


fun CredentialKeychain.Companion.forCurrentPlatform(context: Context, serviceName: String, accountName: String = serviceName): CredentialKeychain(source)

Creates app-private storage isolated by serviceName and accountName, encrypted with a non-exportable Android Keystore AES-256-GCM key. Ciphertext is written to a file under Context.getNoBackupFilesDir, so entries are excluded from Auto Backup — Keystore keys are hardware/OS-bound and cannot be restored onto another device or after a factory reset.

context is retained only as Context.getApplicationContext, never the passed-in instance, so it is safe to call this with an Activity context without leaking it.

val keychain = CredentialKeychain.forCurrentPlatform(
context = applicationContext,
serviceName = "my-app",
accountName = "user-123",
)

Parameters

context

any Android Context; only its application context is retained.

serviceName

identifies the calling application or integration; must be nonblank and free of NUL/CR/LF.

accountName

identifies the credential owner; defaults to serviceName. Same validity rules as serviceName.

Throws

if serviceName or accountName is blank or contains NUL, CR, or LF.


fun PasswordStore.Companion.forCurrentPlatform(context: Context, serviceName: String, accountName: String = serviceName): PasswordStore(source)

Creates an app-private password store isolated by serviceName and accountName, encrypted with its own non-exportable Android Keystore AES-256-GCM key. Like the CredentialKeychain overload, ciphertext lives under Context.getNoBackupFilesDir and is excluded from backup.

context is retained only as Context.getApplicationContext.

val passwords = PasswordStore.forCurrentPlatform(
context = applicationContext,
serviceName = "my-app",
accountName = "user-123",
)

Parameters

context

any Android Context; only its application context is retained.

serviceName

identifies the calling application or integration; must be nonblank and free of NUL/CR/LF.

accountName

identifies the credential owner; defaults to serviceName. Same validity rules as serviceName.

Throws

if serviceName or accountName is blank or contains NUL, CR, or LF.