Skip to content

Instantly share code, notes, and snippets.

@marcobrador
Last active March 26, 2020 17:23
Show Gist options
  • Save marcobrador/7fb741eb0c0c20840d59f4cc8164b29c to your computer and use it in GitHub Desktop.
Save marcobrador/7fb741eb0c0c20840d59f4cc8164b29c to your computer and use it in GitHub Desktop.
fun generateAesKey(): SecretKey {
val keyGenerator = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, "AndroidKeyStore")
val kgps = KeyGenParameterSpec.Builder("my_aes_key", KeyProperties.PURPOSE_ENCRYPT or KeyProperties.PURPOSE_DECRYPT)
.setBlockModes(KeyProperties.BLOCK_MODE_GCM)
.setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_NONE)
// This is required to be able to provide the IV ourselves
.setRandomizedEncryptionRequired(false)
.build()
keyGenerator.init(kgps)
return keyGenerator.generateKey()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment