KeySpecpublic class KeyStoreKeySpec extends Object implements KeySpec
A key specification contains the key alias, source, purposes, length, validity period, and block cipher mode.
SystemCapability.Security#KEYSTORE_PROVIDER| 限定符和类型 | 方法 | 说明 |
|---|---|---|
String[] |
getKeyCryptoAttr(int type) |
Obtains the cryptographic attribute set of a key, depending on the input parameter.
|
String |
getSecKeyAlias() |
Obtains the alias of a key.
|
int |
getSecKeyAuthDuration() |
Obtains the validity period of user authentication for a key.
|
int |
getSecKeySizeInBits() |
Obtains the key length.
|
int |
getSecKeySource() |
Obtains the source of a key.
|
int |
getSecKeyUsagePurposes() |
Obtains the purposes for using a key.
|
boolean |
isInMobileSecureProcessor() |
Checks whether the key is stored in a secure mobile processor.
|
boolean |
isKeyAccessible(int flag) |
Checks the accessibility of a key based on the input parameter.
|
boolean |
isUsedAfterAuthenticatedWithMobileSecureProcessor() |
Checks whether the key can be used only after it is user-authenticated through a secure mobile processor.
|
public String getSecKeyAlias()
This alias can be used to retrieve the key entry in the KeyStore.
public int getSecKeySource()
The source of a key can be generated by the KeyStore, imported to the KeyStore from outside,
or unknown.
KeyStoreConstants#SEC_KEY_SOURCE_GENERATED,
KeyStoreConstants#SEC_KEY_SOURCE_IMPORTED, or unknown.public int getSecKeyUsagePurposes()
Examples include encryption, decryption, signing, and signature verification.
KeyStoreConstants#PURPOSE_CAN_ENCRYPT,
KeyStoreConstants#PURPOSE_CAN_DECRYPT, KeyStoreConstants#PURPOSE_CAN_SIGN, or
KeyStoreConstants#PURPOSE_CAN_VERIFY.public int getSecKeySizeInBits()
public String[] getKeyCryptoAttr(int type)
type - Indicates the cryptographic attribute of the key, which can be
KeyStoreConstants#CRYPTO_PARAMETER_DIGEST,
KeyStoreConstants#CRYPTO_PARAMETER_ENCRYPT_PADDING,
KeyStoreConstants#CRYPTO_PARAMETER_BLOCK_MODE, or
KeyStoreConstants#CRYPTO_PARAMETER_SIGNATURE_PADDING.public int getSecKeyAuthDuration()
If a key requires user authentication (see KeyStoreConstants#FLAG_KEY_ACCESSIBLE_NEEDED_USER_AUTH),
this method can be used to obtain the validity period of user authentication.
-1 if user
authentication is required every time the key is used.public boolean isKeyAccessible(int flag)
flag - Indicates the purposes for using the key, which can be
KeyStoreConstants#FLAG_KEY_ACCESSIBLE_NEEDED_USER_AUTH,
KeyStoreConstants#FLAG_KEY_ACCESSIBLE_NEED_DEVICE_UNLOCK, or
KeyStoreConstants#FLAG_KEY_ACCESSIBLE_NEED_RANDOMIZED_ENCRYPTION.true if the key is accessible; returns false otherwise.public boolean isInMobileSecureProcessor()
true if the key is stored in a secure mobile processor; returns false otherwise.public boolean isUsedAfterAuthenticatedWithMobileSecureProcessor()
true if the key can be used only after it is user-authenticated through
a secure mobile processor; returns false otherwise.