gpt4 book ai didi

android - 在 Android 中存储 AES key

转载 作者:行者123 更新时间:2023-11-29 14:36:14 24 4
gpt4 key购买 nike

我想将 AES key 存储在 pre-M 设备上的 AndroidKeyStore 中

我尝试使用 KeyGenerator 生成的 key

KeyGenerator keyGen = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES);
keyGen.init(256);
SecretKey secretKey = keyGen.generateKey();

但我无法从 KeyStore 访问该 key ,后来我尝试使用 KeyPairGenerator

KeyPairGenerator kpg = KeyPairGenerator.getInstance(
KeyProperties.KEY_ALGORITHM_AES, "AndroidKeyStore");
kpg.initialize(new KeyPairGeneratorSpec.Builder(this)
.setAlias("alias")
.build());
KeyPair kp = kpg.genKeyPair();

但是

java.security.NoSuchAlgorithmException: KeyPairGenerator AES implementation not found

最佳答案

Android keystore 仅从 API 级别 23 开始支持 AES(参见 https://developer.android.com/training/articles/keystore.html#SupportedAlgorithms)。在旧平台上,您可以使用 Android Keystore RSA key 包装 AES key 。但是,这意味着 AES key 的 key Material 将在您的应用进程中可用,这会消除使用 Android Keystore 的许多安全优势。

关于android - 在 Android 中存储 AES key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37324096/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com