Created
April 1, 2026 20:55
-
-
Save LethalMaus/47ef1cc1896a02a46eeb1995792e3f30 to your computer and use it in GitHub Desktop.
TrustKeyService: Android Keystore AES key generation snippet
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
| val builder = KeyGenParameterSpec.Builder( | |
| alias, | |
| KeyProperties.PURPOSE_ENCRYPT or KeyProperties.PURPOSE_DECRYPT, | |
| ).setBlockModes(KeyProperties.BLOCK_MODE_GCM) | |
| .setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_NONE) | |
| .setRandomizedEncryptionRequired(true) | |
| .setKeySize(256) | |
| if (requestStrongBox && Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { | |
| builder.setIsStrongBoxBacked(true) | |
| } | |
| keyGenerator.init(builder.build()) | |
| keyGenerator.generateKey() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment