Friday, September 2, 2016

How to use Android KeyStore API with API 18?

Leave a Comment

How do I get the equivalent code below when I'm targeting API 18? Code below works only for API 23 and above. Also how secure would the API 18 code be, given that we can't use KeyGenParameterSpec and the API 18 code might use deprecated APIs?

KeyGenerator keyGenerator = KeyGenerator.getInstance(     KeyProperties.KEY_ALGORITHM_AES, "AndroidKeyStore");  keyGenerator.init(new KeyGenParameterSpec.Builder(alias,     KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT)     .setBlockModes(KeyProperties.BLOCK_MODE_CBC)     .setKeySize(256)     .setUserAuthenticationRequired(true)     .setUserAuthenticationValidityDurationSeconds(400)     .setRandomizedEncryptionRequired(false)     .setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_PKCS7)     .build());  SecretKey key = keyGenerator.generateKey(); 

1 Answers

Answers 1

Symmetric key generation and storage in the Android KeyStore is supported from Android 6.0 (API Level 23) onwards.

Asymmetric key generation and storage in the Android KeyStore is supported from Android 4.3 (API Level 18) onwards.

See this document for more info: Android Keystore System

Though there are some problems you can use Asymmetric key generation. Follow the reference bellow..

Asymmetric Key Generation

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment