Skip to content

Instantly share code, notes, and snippets.

@Jaypatelbond
Created December 4, 2025 07:55
Show Gist options
  • Select an option

  • Save Jaypatelbond/07db42c7cf7eb8b97ef0e4ab149410d9 to your computer and use it in GitHub Desktop.

Select an option

Save Jaypatelbond/07db42c7cf7eb8b97ef0e4ab149410d9 to your computer and use it in GitHub Desktop.
class CryptoManager(context: Context) {
private val aead = AndroidKeysetManager.Builder()
.withSharedPref(context, "master_keyset", "master_key_preference")
.withKeyTemplate(KeyTemplates.get("AES128_GCM_HKDF_4KB"))
.withMasterKeyUri("android-keystore://master_key")
.build()
.keysetHandle
.getPrimitive(StreamingAead::class.java)
fun encrypt(outputStream: OutputStream): OutputStream {
return aead.newEncryptingStream(outputStream, ByteArray(0))
}
fun decrypt(inputStream: InputStream): InputStream {
return aead.newDecryptingStream(inputStream, ByteArray(0))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment