小编And*_*dr6的帖子

setIsStrongBoxBacked() for 不会按预期抛出 StrongBoxUnavailableException

我最近在使用 Android 密钥库系统。

根据此链接提供的GrapheneOS/AttestationSamples,使用小米9手机和华为P20(更新至Android 9)进行测试,可能不支持StrongBox 。

此外,以下代码返回 false 表示该设备没有 StrongBox 功能。

private boolean hasStrongBox(Context context){
    return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_STRONGBOX_KEYSTORE);
}
Run Code Online (Sandbox Code Playgroud)

但是,在测试过程中,当我使用下面的代码生成 AES 加密密钥时,两部手机都不会抛出 StrongBoxUnavailableException:

protected int createAndroidKeyStoreSymmetricKey() throws NoSuchProviderException, NoSuchAlgorithmException, InvalidAlgorithmParameterException {
    KeyGenerator keyGenerator = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, "AndroidKeyStore");

    KeyGenParameterSpec.Builder builder = new KeyGenParameterSpec.Builder(ALIAS_MASTER_KEY, KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT)
            .setBlockModes(KeyProperties.BLOCK_MODE_CBC)
            .setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_PKCS7);
            .setIsStrongBoxBacked(true);
    
    keyGenerator.init(builder.build());
    secretKey = keyGenerator.generateKey();

    if(secretKey != null ){
        return 0;
    } else {
        return -1;
    }
}
Run Code Online (Sandbox Code Playgroud)

在生成 RSA 加密密钥时,它们都抛出了 StrongBoxUnavailableException:

private KeyPair genKeyPair(String alias, boolean isStrongBoxBacked) throws Exception { …
Run Code Online (Sandbox Code Playgroud)

android keystore

5
推荐指数
0
解决办法
667
查看次数

标签 统计

android ×1

keystore ×1