Reputation: 1410
i want to store AES key in AndroidKeyStore on pre-M device
i tried to use key generated with KeyGenerator
KeyGenerator keyGen = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES);
keyGen.init(256);
SecretKey secretKey = keyGen.generateKey();
but i cannot access to that key from KeyStore, later i tried to use KeyPairGenerator
KeyPairGenerator kpg = KeyPairGenerator.getInstance(
KeyProperties.KEY_ALGORITHM_AES, "AndroidKeyStore");
kpg.initialize(new KeyPairGeneratorSpec.Builder(this)
.setAlias("alias")
.build());
KeyPair kp = kpg.genKeyPair();
but
java.security.NoSuchAlgorithmException: KeyPairGenerator AES implementation not found
Upvotes: 2
Views: 6883
Reputation: 5732
Android Keystore supports AES only since API Level 23 (see https://developer.android.com/training/articles/keystore.html#SupportedAlgorithms). On older platforms, you could wrap the AES key using an Android Keystore RSA key. However, this means the AES key's key material will be available inside your app's process, which removes many of the security benefits of using Android Keystore.
Upvotes: 8