Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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