AeadSerializer



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(
    aead: ERROR CLASS: Symbol not found for Aead,
    wrappedSerializer: ERROR CLASS: Symbol not found for Serializer<T>,
    associatedData: ByteArray
)
Cmn

Public functions

open suspend T
@Throws(exceptionClasses = [CorruptionException<ERROR CLASS>])
readFrom(input: ERROR CLASS: Symbol not found for InputStream)

Reads the data from the input, decrypts it using the provided Aead instance, and delegates to the wrappedSerializer to deserialize the decrypted bytes.

Cmn
open suspend Unit
writeTo(t: T, output: ERROR CLASS: Symbol not found for OutputStream)

Delegates to the wrappedSerializer to serialize the data, encrypts it using the provided Aead instance, and writes the encrypted bytes to the output.

Cmn

Public properties

open T

Returns the default value for the data type T.

Cmn

Public constructors

AeadSerializer

<T : Any?> AeadSerializer(
    aead: ERROR CLASS: Symbol not found for Aead,
    wrappedSerializer: ERROR CLASS: Symbol not found for Serializer<T>,
    associatedData: ByteArray = byteArrayOf()
)
Parameters
aead: ERROR CLASS: Symbol not found for Aead

The Aead instance used for encryption and decryption.

wrappedSerializer: ERROR CLASS: Symbol not found for Serializer<T>

The underlying serializer for the data type T.

associatedData: ByteArray = byteArrayOf()

The associated data to be used for encryption and decryption. It is very important to use a unique associatedData value so that if the same key is used to encrypt multiple sets of data, it will still be safe from a ciphertext swapping/substitution attack. Users should use something unique like the filename as the associated data. If they are sure that the Aead instance is not reused across multiple data stores, they can set a default associated data value of byteArrayOf().

Public functions

readFrom

@Throws(exceptionClasses = [CorruptionException<ERROR CLASS>])
open suspend fun readFrom(input: ERROR CLASS: Symbol not found for 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
java.security.GeneralSecurityException

if the data cannot be decrypted

androidx.datastore.core.CorruptionException

if the wrappedSerializer fails to read the data.

writeTo

open suspend fun writeTo(t: T, output: ERROR CLASS: Symbol not found for 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.