title: How to use Android KeyStore API with API 18?
body: <p>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 <code>KeyGenParameterSpec</code> and the API 18 code might use deprecated APIs? </p>
  
  <pre><code>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();
  </code></pre>