Я использую библиотеку криптографии: androidx.security:security-crypto:1.0.0-beta01 в соответствии с этим примером https://developer.android.com/guide/topics/security/cryptography Я не могу правильно расшифровать зашифрованный файл. После расшифровки все страницы файла PDF остаются пустыми. Снимок экрана показывает изменения размера файла. Может кто-нибудь сказать мне, что я делаю не так?
![enter image description here](https://i.stack.imgur.com/VtJG0.png)
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 ->
bufferWriter.write(text)
}
}
private val File.encrypted: EncryptedFile
get() = EncryptedFile.Builder(
this,
context,
masterKeyAlias,
EncryptedFile.FileEncryptionScheme.AES256_GCM_HKDF_4KB
).build()
}
Фрагмент кода из примера расшифровывает файл в течение очень долгого времени ( 6 se c +/-) И этот код тоже не решает мою проблему
val contents = file.encrypted.openFileInput().bufferedReader().useLines { lines ->
lines.fold("") { working, line ->
"$working\n$line"
}
}
someFile.bufferedWriter().write(contents)