include::../description.adoc[]

include::../ask-yourself.adoc[]

include::../recommended.adoc[]

== Sensitive Code Example

----
val targetFile = File(activity.filesDir, "data.txt")
targetFile.writeText(fileContent)  // Sensitive
----

== Compliant Solution

[source,kotlin]
----
val mainKey = MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC)

val encryptedFile = EncryptedFile.Builder(
    File(activity.filesDir, "data.txt"),
    activity,
    mainKey,
    EncryptedFile.FileEncryptionScheme.AES256_GCM_HKDF_4KB
).build()

encryptedFile.openFileOutput().apply {
    write(fileContent)
    flush()
    close()
}
----

include::../see.adoc[]
