Persist notification big pictures encrypted
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
package se.ajpanton.notificationlog.data
|
||||
|
||||
import android.content.Context
|
||||
import java.io.File
|
||||
|
||||
/** Stores copied notification image bytes independently of the source app's URI lifetime. */
|
||||
class EncryptedImageStore(context: Context) {
|
||||
private val directory = File(context.filesDir, "notification-images").also(File::mkdirs)
|
||||
private val cipher = AesGcmCipher(LogEncryptionKeyProvider().getOrCreate())
|
||||
|
||||
fun save(id: String, bytes: ByteArray) {
|
||||
val payload = cipher.encrypt(bytes)
|
||||
File(directory, "$id.bin").outputStream().use { output ->
|
||||
output.write(payload.initializationVector.size)
|
||||
output.write(payload.initializationVector)
|
||||
output.write(payload.cipherText)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user