KeyChainManager
public
final
class
KeyChainManager
extends Object
| java.lang.Object | |
| ↳ | android.security.KeyChainManager |
Manages KeyChain certificates and grants.
Summary
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 | |
|---|---|
Constants
KEYPAIR_SCOPE_DEVICE
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)
KEYPAIR_SCOPE_USER
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 methods
getCertificateChain
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.
| 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: |
| 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. |
getGrantedKeyPairs
public List<GrantedKeyInfo> getGrantedKeyPairs (int scope)
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: |
| Returns | |
|---|---|
List<GrantedKeyInfo> |
A non-null list of GrantedKeyInfo objects. |
| Throws | |
|---|---|
IllegalArgumentException |
if scope is invalid. |
getPrivateKey
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.
| 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: |
| 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. |