Skip to content

Instantly share code, notes, and snippets.

@yakivmospan
Last active November 20, 2017 19:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yakivmospan/e513d869759acb9b29ac65a01488c46c to your computer and use it in GitHub Desktop.
Save yakivmospan/e513d869759acb9b29ac65a01488c46c to your computer and use it in GitHub Desktop.
@TargetApi(23)
fun createAndroidKeyStoreSymmetricKey(alias: String): SecretKey {
val keyGenerator = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, "AndroidKeyStore")
val builder = KeyGenParameterSpec.Builder(alias, KeyProperties.PURPOSE_ENCRYPT or KeyProperties.PURPOSE_DECRYPT)
.setBlockModes(KeyProperties.BLOCK_MODE_CBC)
.setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_PKCS7)
keyGenerator.init(builder.build())
return keyGenerator.generateKey()
}
fun getAndroidKeyStoreSymmetricKey(alias: String): SecretKey? = keyStore.getKey(alias, null) as SecretKey?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment