Skip to content

Instantly share code, notes, and snippets.

@LethalMaus
Created April 1, 2026 20:55
Show Gist options
  • Select an option

  • Save LethalMaus/47ef1cc1896a02a46eeb1995792e3f30 to your computer and use it in GitHub Desktop.

Select an option

Save LethalMaus/47ef1cc1896a02a46eeb1995792e3f30 to your computer and use it in GitHub Desktop.
TrustKeyService: Android Keystore AES key generation snippet
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