【发布时间】:2017-05-08 11:35:04
【问题描述】:
我正在使用以下代码生成 AES 密钥并将其存储到 Android KeyStore:
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { //redundant
try {
// generate some AES key for encryption
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, "AndroidKeyStore");
keyPairGenerator.initialize(new KeyGenParameterSpec.Builder(
"VideoEncryptionKey",
KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT)
.setBlockModes(KeyProperties.BLOCK_MODE_GCM)
.setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_NONE)
.setRandomizedEncryptionRequired(false)
.build());
keyPairGenerator.generateKeyPair();
} catch (Exception e) {
e.printStackTrace();
}
}
执行时,代码失败并显示java.security.NoSuchAlgorithmException: KeyPairGenerator AES implementation not found。
代码是用 targetSdkVersion 23 和 compileSdkVersion 25 构建的,并且在带有 Android 6.0.1 的 Blackberry Priv 上运行,因此根据文档,不应该有任何此类异常,因为 AES 算法需要 API 级别 23 或更高。
感谢任何帮助。
【问题讨论】:
标签: android encryption android-keystore