forCurrentPlatform

fun ProtectedKeychain.Companion.forCurrentPlatform(context: Context, activity: () -> FragmentActivity?, serviceName: String, accountName: String): ProtectedKeychain(source)

Creates biometric-protected storage isolated by serviceName and accountName.

Each namespace has one non-exportable Android Keystore RSA key whose private key can only be used after a Class 3 biometric authentication and is invalidated when biometric enrollment changes. Every entry is encrypted with a fresh AES-256-GCM key that the RSA public key wraps, so ProtectedKeychain.write needs no prompt. Ciphertext lives under Context.getNoBackupFilesDir and is never backed up.

val protected = ProtectedKeychain.forCurrentPlatform(
context = applicationContext,
activity = { currentActivity },
serviceName = "my-app",
accountName = "user-123",
)

Parameters

context

any Android Context; only its application context is retained.

activity

returns the FragmentActivity that hosts the prompt, called on the main thread for each ProtectedKeychain.read. Return the currently resumed activity rather than capturing one, so the store does not leak it. A null result fails the read with Reason.Failed.

serviceName

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

accountName

identifies the credential owner. Same validity rules as serviceName.

Throws

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