Last active
March 26, 2020 17:23
-
-
Save marcobrador/7fb741eb0c0c20840d59f4cc8164b29c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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