AeadSerializer
class AeadSerializer<T : Any?> : Serializer
A Serializer implementation that provides transparent encryption and decryption using Tink's Aead (Authenticated Encryption with Associated Data).
This class wraps another Serializer, encrypting the data before it is written to the OutputStream and decrypting it after it is read from the InputStream.
Summary
Public constructors |
|---|
<T : Any?> AeadSerializer( |
Public functions |
|
|---|---|
open suspend T |
readFrom(input: InputStream)Reads the data from the |
open suspend Unit |
writeTo(t: T, output: OutputStream)Delegates to the |
Public properties |
|
|---|---|
open T |
Returns the default value for the data type |
Public constructors
AeadSerializer
<T : Any?> AeadSerializer(
aead: Aead,
wrappedSerializer: Serializer<T>,
associatedData: ByteArray = byteArrayOf()
)
| Parameters | |
|---|---|
aead: Aead |
The |
wrappedSerializer: Serializer<T> |
The underlying serializer for the data type |
associatedData: ByteArray = byteArrayOf() |
The associated data to be used for encryption and decryption. It is very important to use a unique |
Public functions
readFrom
open suspend fun readFrom(input: InputStream): T
Reads the data from the input, decrypts it using the provided Aead instance, and delegates to the wrappedSerializer to deserialize the decrypted bytes.
| Throws | |
|---|---|
androidx.datastore.core.CorruptionException |
if the data cannot be decrypted or if the |
writeTo
open suspend fun writeTo(t: T, output: OutputStream): Unit
Delegates to the wrappedSerializer to serialize the data, encrypts it using the provided Aead instance, and writes the encrypted bytes to the output.
Public properties
defaultValue
open val defaultValue: T
Returns the default value for the data type T.