I want to try using Android Keystore system to encrypt and decrypt data, i tried a sample that works fine for API >= 23, but it's not working for API below 23.
here is a sample code :
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
keyGenerator = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, ANDROID_KEY_STORE);
keyGenerator.init(new KeyGenParameterSpec.Builder(alias, KeyProperties.PURPOSE_ENCRYPT |
KeyProperties.PURPOSE_DECRYPT)
.setBlockModes(KeyProperties.BLOCK_MODE_GCM)
.setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_NONE)
.build());
} else {
keyGenerator = KeyGenerator.getInstance(ANDROID_KEY_STORE);
// how to implement here
keyGenerator.init(...);
}
i need to deal with API < 23, thank you.