【问题标题】:KeyStore API AES Key Generation NoSuchAlgorithmExceptionKeyStore API AES 密钥生成 NoSuchAlgorithmException
【发布时间】: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 23compileSdkVersion 25 构建的,并且在带有 Android 6.0.1 的 Blackberry Priv 上运行,因此根据文档,不应该有任何此类异常,因为 AES 算法需要 API 级别 23 或更高。

感谢任何帮助。

【问题讨论】:

    标签: android encryption android-keystore


    【解决方案1】:

    KeyPairGenerator 用于使用密钥对(私钥和公钥)的算法,例如 RSADSA

    对于像 AES 中的对称密钥,请使用 KeyGenerator 类。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-02
      • 1970-01-01
      • 1970-01-01
      • 2018-05-31
      • 2023-04-03
      • 1970-01-01
      • 1970-01-01
      • 2011-07-13
      相关资源
      最近更新 更多