Sachin Chauhan
Sachin Chauhan

Reputation: 366

How to check for StrongBox Keymaster hardware availability before key generation?

I am looking for a solution where I can use StrongBox hardware if present in the device to store my cryptographic keys. Currently, I am creating keys having setIsStrongBoxBacked(true) method in KeyGenParameterSpec builder, and when the StrongBoxUnavailableException occurs I fallback to generate keys without it.

Upvotes: 6

Views: 3213

Answers (1)

StoneLi
StoneLi

Reputation: 166

You can check whether the device has feature of "PackageManager.FEATURE_STRONGBOX_KEYSTORE" like this:

boolean hasStrongBox() {
       return mActivity.getPackageManager()
           .hasSystemFeature(PackageManager.FEATURE_STRONGBOX_KEYSTORE)
}

or

boolean hasStrongBox;
hasStrongBox = getContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_STRONGBOX_KEYSTORE);

Upvotes: 15

Related Questions