rspec/rules/S6300/java/rule.adoc
2021-10-04 15:13:19 +02:00

35 lines
774 B
Plaintext

include::../description.adoc[]
include::../ask-yourself.adoc[]
include::../recommended.adoc[]
== Sensitive Code Example
----
Files.write(path, content); // Sensitive
FileOutputStream out = new FileOutputStream(file); // Sensitive
FileWriter fw = new FileWriter("outfilename", false); // Sensitive
----
== Compliant Solution
----
String masterKeyAlias = MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC);
File file = new File(context.getFilesDir(), "secret_data");
EncryptedFile encryptedFile = EncryptedFile.Builder(
file,
context,
masterKeyAlias,
EncryptedFile.FileEncryptionScheme.AES256_GCM_HKDF_4KB
).build();
// write to the encrypted file
FileOutputStream encryptedOutputStream = encryptedFile.openFileOutput();
----
include::../see.adoc[]