public
final
class
KeyChainManager
extends Object
| java.lang.Object | |
| ↳ | android.security.KeyChainManager |
Manages KeyChain certificates and grants.
Constants | |
|---|---|
int |
KEYPAIR_SCOPE_DEVICE
Scope indicating the key pair is installed device-wide and is visible to all affiliated users on the device. |
int |
KEYPAIR_SCOPE_USER
Scope indicating the key pair is installed for the current user only. |
Public methods | |
|---|---|
List<X509Certificate>
|
getCertificateChain(String alias, int scope)
Returns the certificate chain of the given scoped certificate. |
List<GrantedKeyInfo>
|
getGrantedKeyPairs(int scope)
Returns a list of granted keys that the calling app has access to for the specified scope. |
PrivateKey
|
getPrivateKey(String alias, int scope)
Returns the private key for the given alias and scope. |
Inherited methods | |
|---|---|
public static final int KEYPAIR_SCOPE_DEVICE
Scope indicating the key pair is installed device-wide and is visible to all affiliated users on the device.
Constant Value: 1 (0x00000001)
public static final int KEYPAIR_SCOPE_USER
Scope indicating the key pair is installed for the current user only. This is the default scope for existing KeyChain credentials.
Constant Value: 2 (0x00000002)
public List<X509Certificate> getCertificateChain (String alias,
int scope)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.
aliasString: The alias of the desired certificate chain.
null.scopeint: The scope to search (KEYPAIR_SCOPE_USER or
KEYPAIR_SCOPE_DEVICE).
| Returns | |
|---|---|
List<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. |
| Throws | |
|---|---|
IllegalArgumentException |
if scope is invalid. |
public List<GrantedKeyInfo> getGrantedKeyPairs (int scope)
Returns a list of granted keys that the calling app has access to for the specified scope.
scopeint: The scope of the key pair: KEYPAIR_SCOPE_USER or
KEYPAIR_SCOPE_DEVICE.
| Returns | |
|---|---|
List<GrantedKeyInfo> |
A non-null list of GrantedKeyInfo objects. |
| Throws | |
|---|---|
IllegalArgumentException |
if scope is invalid. |
public PrivateKey getPrivateKey (String alias,
int scope)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.
aliasString: The alias of the desired key pair.
null.scopeint: The scope to search (KEYPAIR_SCOPE_USER or
KEYPAIR_SCOPE_DEVICE).
| Returns | |
|---|---|
PrivateKey |
The PrivateKey, or null if no key exists for the given alias/scope
or if access to the key is not granted. |
| Throws | |
|---|---|
IllegalArgumentException |
if scope is invalid. |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2026-08-28 UTC.