KeyGenParameterSpec.Builder.SetMaxUsageCount(Int32) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Sets the maximum number of times the key is allowed to be used.
[Android.Runtime.Register("setMaxUsageCount", "(I)Landroid/security/keystore/KeyGenParameterSpec$Builder;", "", ApiSince=31)]
public Android.Security.Keystore.KeyGenParameterSpec.Builder SetMaxUsageCount(int maxUsageCount);
[<Android.Runtime.Register("setMaxUsageCount", "(I)Landroid/security/keystore/KeyGenParameterSpec$Builder;", "", ApiSince=31)>]
member this.SetMaxUsageCount : int -> Android.Security.Keystore.KeyGenParameterSpec.Builder
Parameters
- maxUsageCount
- Int32
maximum number of times the key is allowed to be used or KeyProperties.UNRESTRICTED_USAGE_COUNT if there is no restriction on the usage.
Returns
- Attributes
Remarks
Sets the maximum number of times the key is allowed to be used. After every use of the key, the use counter will decrease. This authorization applies only to secret key and private key operations. Public key operations are not restricted. For example, after successfully encrypting and decrypting data using methods such as Cipher.doFinal(), the use counter of the secret key will decrease. After successfully signing data using methods such as Signature.sign(), the use counter of the private key will decrease. When the use counter is depleted, the key will be marked for deletion by Android Keystore and any subsequent attempt to use the key will throw KeyPermanentlyInvalidatedException. There is no key to be loaded from the Android Keystore once the exhausted key is permanently deleted, as if the key never existed before.
By default, there is no restriction on the usage of key.
Some secure hardware may not support this feature at all, in which case it will be enforced in software, some secure hardware may support it but only with maxUsageCount = 1, and some secure hardware may support it with larger value of maxUsageCount.
The PackageManager feature flags: PackageManager.FEATURE_KEYSTORE_SINGLE_USE_KEY and PackageManager.FEATURE_KEYSTORE_LIMITED_USE_KEY can be used to check whether the secure hardware cannot enforce this feature, can only enforce it with maxUsageCount = 1, or can enforce it with larger value of maxUsageCount.
Android reference for android.security.keystore.KeyGenParameterSpec.Builder.setMaxUsageCount.
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.