title: How to decrypt an encrypted file correctly?
body: <p>I use the cryptography library:
  androidx.security:security-crypto:1.0.0-beta01
  according to this example <a href="https://developer.android.com/guide/topics/security/cryptography" rel="nofollow noreferrer">https://developer.android.com/guide/topics/security/cryptography</a>
  I cannot correctly decrypt the file I encrypted.
  After decryption, all pages of the pdf file are blank.
  the screenshot shows the file size changes.
  Can anyone tell me what I'm doing wrong?</p>
  
  <p><a href="https://i.stack.imgur.com/VtJG0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VtJG0.png" alt="enter image description here"></a></p>
  
  <pre><code>object Encryptor {
  
  private lateinit var context: Context
  private val keyGenParameterSpec = MasterKeys.AES256_GCM_SPEC
  private val masterKeyAlias = MasterKeys.getOrCreate(keyGenParameterSpec)
  
  fun decrypt(file: File): File {
      val bytes = file.encrypted.openFileInput().readBytes()
      return File("${context.filesDir}/storage", "decrypt.pdf").apply { writeBytes(bytes) }
  }
  
  fun encrypt(fromFile: File, toFile: File) {
      val text = fromFile.readText()
      toFile.encrypted.openFileOutput().bufferedWriter().use { bufferWriter -&gt;
          bufferWriter.write(text)
      }
  }
  
  private val File.encrypted: EncryptedFile
      get() = EncryptedFile.Builder(
          this,
          context,
          masterKeyAlias,
          EncryptedFile.FileEncryptionScheme.AES256_GCM_HKDF_4KB
      ).build()
  }
  </code></pre>
  
  <p>The code snippet from the example decrypts the file for a very long time (6 sec +/-)
  And this code also does not solve my problem</p>
  
  <pre><code>val contents = file.encrypted.openFileInput().bufferedReader().useLines { lines -&gt;
          lines.fold("") { working, line -&gt;
              "$working\n$line"
          }
      }
  someFile.bufferedWriter().write(contents)
  </code></pre>