KeyChainManager


class KeyChainManager
kotlin.Any
   ↳ android.security.KeyChainManager

Manages KeyChain certificates and grants.

Summary

Constants
static Int

Scope indicating the key pair is installed device-wide and is visible to all affiliated users on the device.

static Int

Scope indicating the key pair is installed for the current user only.

Public methods
MutableList<X509Certificate!>
getCertificateChain(alias: String, scope: Int)

Returns the certificate chain of the given scoped certificate.

MutableList<GrantedKeyInfo!>

Returns a list of granted keys that the calling app has access to for the specified scope.

PrivateKey?
getPrivateKey(alias: String, scope: Int)

Returns the private key for the given alias and scope.

Constants

KEYPAIR_SCOPE_DEVICE

static val KEYPAIR_SCOPE_DEVICE: Int

Scope indicating the key pair is installed device-wide and is visible to all affiliated users on the device.

Value: 1

KEYPAIR_SCOPE_USER

static val KEYPAIR_SCOPE_USER: Int

Scope indicating the key pair is installed for the current user only. This is the default scope for existing KeyChain credentials.

Value: 2

Public methods

getCertificateChain

fun getCertificateChain(
    alias: String,
    scope: Int
): MutableList<X509Certificate!>

Returns the certificate chain of the given scoped certificate. Callable by the application that installed the certificate, any app that has been granted access to the given alias, as well as DPCs and their delegates.

Parameters
alias String: The alias of the desired certificate chain.
This value cannot be null.
scope Int: The scope to search (KEYPAIR_SCOPE_USER or KEYPAIR_SCOPE_DEVICE).
Value is one of the following:
Return
MutableList<X509Certificate!> The list of X509Certificates representing the chain, or an empty list if no certificate exists for the given alias/scope or if access to the key is not granted.
This value cannot be null.
Exceptions
java.lang.IllegalArgumentException if scope is invalid.

getGrantedKeyPairs

fun getGrantedKeyPairs(scope: Int): MutableList<GrantedKeyInfo!>

Returns a list of granted keys that the calling app has access to for the specified scope.

Parameters
scope Int: The scope of the key pair: KEYPAIR_SCOPE_USER or KEYPAIR_SCOPE_DEVICE.
Value is one of the following:
Return
MutableList<GrantedKeyInfo!> A non-null list of GrantedKeyInfo objects.
Exceptions
java.lang.IllegalArgumentException if scope is invalid.

getPrivateKey

fun getPrivateKey(
    alias: String,
    scope: Int
): PrivateKey?

Returns the private key for the given alias and scope.
This method may take several seconds to complete, so it should only be called from a worker thread.

Parameters
alias String: The alias of the desired key pair.
This value cannot be null.
scope Int: The scope to search (KEYPAIR_SCOPE_USER or KEYPAIR_SCOPE_DEVICE).
Value is one of the following:
Return
PrivateKey? The PrivateKey, or null if no key exists for the given alias/scope or if access to the key is not granted.
Exceptions
java.lang.IllegalArgumentException if scope is invalid.