在Android M之前生成SecretKey

时间:2017-11-25 21:52:41

标签: android secret-key

这是为Android M及以上版本创建SeretKey的方法:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    final KeyGenerator keyGenerator = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, ANDROID_KEY_STORE);
    keyGenerator.init(
            new KeyGenParameterSpec.Builder(USER_KEY_ALIAS,
                    KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT)
                    .setBlockModes(KeyProperties.BLOCK_MODE_GCM).setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_NONE)
                    .setRandomizedEncryptionRequired(false)
                    .build());
}

我如何实现Android M之前的等效?

0 个答案:

没有答案