security-samples icon indicating copy to clipboard operation
security-samples copied to clipboard

method encryptFile() has bug

Open 1Patience-and-1careful opened this issue 5 years ago • 1 comments

 private fun encryptFile() {
        val title = binding.titleEditText.text.toString()
        val body = binding.bodyEditText.text.toString()

        if (title.isBlank()) return

        try {
            deleteFile(existingFileTitle)
            val encryptedFile = getEncryptedFile(title)
            encryptedFile.openFileOutput().use { output ->
                output.write(body.toByteArray())
            }
        } catch (e: Exception) {
            e.printStackTrace()
            showSnackbar(R.string.error_unable_to_save_file)
        }
    }

should change deleteFile(existingFileTitle) to deleteFile(title )

1Patience-and-1careful avatar May 13 '20 03:05 1Patience-and-1careful

I'm not sure I follow why? The way I'm thinking of it is this:

Edit note: title="Test", existingFileTitle="Test" Don't change the title, we delete existingFileTitle and create a new file title which both have the same name. (Note: You cannot overwrite an EncryptedFile)

OR Edit note: title="Test", existingFileTitle="Test" Change the name to "Done" -> title="Done", existingFileTitle="Test" To save the note, we delete existingFileTitle and write title which removes the "Test" encrypted note and creates the "Done" encrypted note.

nic0lette avatar May 13 '20 21:05 nic0lette