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

2.5k Views Asked by At

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.

1

There are 1 best solutions below

0
StoneLi On BEST ANSWER

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);