public class SecKeyChain extends Object
An application can install new private keys and certificates through the Intent obtained
using getInstallationIntent(), and select the default private key and certificate
using selectSecPrivateKey(ohos.app.AbilityContext,java.lang.String[],java.security.Principal[],ohos.utils.net.Uri,ohos.security.seckeychain.SecKeyAliasCallback,java.lang.String).
All applications can obtain trusted private keys and certificates through the
X509KeyManager by calling getSecPrivateKey(ohos.app.AbilityContext, java.lang.String) and
getSecCertificateChain(ohos.app.AbilityContext, java.lang.String).
| 限定符和类型 | 字段 | 说明 |
|---|---|---|
static String |
SPEC_ALIAS |
Indicates the flag used to specify the alias of the private key matching the certificate to be installed.
|
static String |
SPEC_CERTIFICATE |
Indicates the flag to specify the X.509 certificate to install.
|
static String |
SPEC_PKCS12 |
Indicates the flag used to specify the PKCS#12 certificate to be installed.
|
| 构造器 | 说明 |
|---|---|
SecKeyChain() |
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
static Intent |
getInstallationIntent() |
Obtains an
Intent used to install certificates. |
static X509Certificate[] |
getSecCertificateChain(AbilityContext context,
String secKeyAlias) |
Obtains the secure certificate chain matching a specified private key alias.
|
static PrivateKey |
getSecPrivateKey(AbilityContext context,
String secKeyAlias) |
Obtains the private key with a specified alias.
|
static boolean |
isSupported(String secKeyAlgorithm) |
Checks whether private keys indicated by a specified
secKeyAlgorithm are supported. |
static void |
selectSecPrivateKey(AbilityContext ability,
String[] secKeyTypes,
Principal[] issuers,
String host,
int port,
SecKeyAliasCallback callback,
String secKeyAlias) |
Starts an ability of available certificates (the host and port can be specified) for users to select the private
key and certificate for authentication.
|
static void |
selectSecPrivateKey(AbilityContext ability,
String[] secKeyTypes,
Principal[] issuers,
Uri uri,
SecKeyAliasCallback callback,
String secKeyAlias) |
Starts an ability of available certificates (the URI can be specified) for users to select the private key and
certificate for authentication.
|
public static final String SPEC_ALIAS
public static final String SPEC_CERTIFICATE
public static void selectSecPrivateKey(AbilityContext ability, String[] secKeyTypes, Principal[] issuers, String host, int port, SecKeyAliasCallback callback, String secKeyAlias)
ability - Indicates the ability to start. The value cannot be null.secKeyTypes - Indicates the type of the asymmetric key matching the certificate to select. The value can be
null, KeyStoreConstants.SEC_KEY_ALGORITHM_RSA,
KeyStoreConstants.SEC_KEY_ALGORITHM_EC,
KeyStoreConstants.SEC_KEY_ALGORITHM_AES,
KeyStoreConstants.SEC_KEY_ALGORITHM_HMAC_SHA1,
KeyStoreConstants.SEC_KEY_ALGORITHM_HMAC_SHA224,
KeyStoreConstants.SEC_KEY_ALGORITHM_HMAC_SHA256,
KeyStoreConstants.SEC_KEY_ALGORITHM_HMAC_SHA384,
or KeyStoreConstants.SEC_KEY_ALGORITHM_HMAC_SHA512.issuers - Indicates the issuer of the certificate to select. The value may be null.host - Indicates the host name of the service provider matching the certificate to select. The value may be
null.port - Indicates the port number of the service provider's host matching the certificate to select. If this
parameter is not specified, the value -1 is used.callback - Indicates the callback through which the selected certificate and private key alias will be
returned. The value cannot be null.secKeyAlias - Indicates the alias of the private key matching the certificate to select. The value may be
null.public static void selectSecPrivateKey(AbilityContext ability, String[] secKeyTypes, Principal[] issuers, Uri uri, SecKeyAliasCallback callback, String secKeyAlias)
ability - Indicates the ability to start. The value cannot be null.secKeyTypes - Indicates the type of the asymmetric key matching the certificate to select. The value can be
null, KeyStoreConstants.SEC_KEY_ALGORITHM_RSA,
KeyStoreConstants.SEC_KEY_ALGORITHM_EC,
KeyStoreConstants.SEC_KEY_ALGORITHM_AES,
KeyStoreConstants.SEC_KEY_ALGORITHM_HMAC_SHA1,
KeyStoreConstants.SEC_KEY_ALGORITHM_HMAC_SHA224,
KeyStoreConstants.SEC_KEY_ALGORITHM_HMAC_SHA256,
KeyStoreConstants.SEC_KEY_ALGORITHM_HMAC_SHA384,
or KeyStoreConstants.SEC_KEY_ALGORITHM_HMAC_SHA512.issuers - Indicates the issuer of the certificate to select. The value may be null.uri - Indicates the URI of the service provider matching the certificate to select. The value may be
null.callback - Indicates the callback through which the selected certificate and private key alias will be
returned. The value cannot be null.secKeyAlias - Indicates the alias of the private key matching the certificate to select. The value may be
null.IllegalArgumentException - Throws this exception if the issuer is not of the X500Principal type.public static Intent getInstallationIntent()
Intent used to install certificates.
You can specify the X.509 (whose encoded form can be obtained using X509Certificate#getEncoded) or
PKCS#12 certificates to install and their aliases in the Intent.
Intent used to install certificates, which cannot be null.public static X509Certificate[] getSecCertificateChain(AbilityContext context, String secKeyAlias) throws InterruptedException, SecKeyChainException
If the private key alias does not exist in the system, or the caller does not have permissions to access the private key alias, this method returns null.
context - Indicates the application context. The value cannot be null.secKeyAlias - Indicates the private key alias. The value cannot be null.null.SecKeyChainException - Throws this exception if there is a problem with the private key or certificate.IllegalStateException - Throws this exception if this method is called from the main thread.InterruptedException - Throws this exception if the current thread is interrupted by other threads.public static PrivateKey getSecPrivateKey(AbilityContext context, String secKeyAlias) throws InterruptedException, SecKeyChainException
If the private key alias does not exist in the system, or the caller does not have permissions to access the alias, this method returns null.
context - Indicates the application context. The value cannot be null.secKeyAlias - Indicates the private key alias. The value cannot be null.null.SecKeyChainException - Throws this exception if there is a problem with the private key or certificate.IllegalStateException - Throws this exception if this method is called from the main thread.InterruptedException - Throws this exception if the current thread is interrupted by other threads.public static boolean isSupported(String secKeyAlgorithm)
secKeyAlgorithm are supported.secKeyAlgorithm - Indicates the private key type (for example, RSA) to check. The value cannot be
null.true if private keys indicated by the specified secKeyAlgorithm are supported;
returns false otherwise.