Skip to content

Encrypted DataStore is an extension function to encrypt and decrypt data String to DataStore using Advanced Encrypted Standard algorithm.

License

Notifications You must be signed in to change notification settings

reskimulud/encrypted-datastore

Repository files navigation

Publish to Maven Central  Maven Central  License  Android  Kotlin 

Encrypted DataStore

Encrypted DataStore is an extension function to encrypt and decrypt data String to DataStore using Advanced Encrypted Standard algorithm.

Installation

implementation 'io.github.reskimulud:encrypted-datastore:0.0.3'

Usage

AES Builder

val aes: AES = AES.Builder()
    .setKey("your_cipher_key") // 256-bit
    .setIv("your_initialize_vector") // 128-bit
    .build()

To store using secureEdit(aes: AES, defaultValue: String) method, and use secureMap(value: String, aes: AES) to retrieve data from DataStore

// to store data
suspend fun setEmail(email: String) =
    dataStore.data.secureEdit(aes, DEDAULT_FALUE) {
        it[EMAIL_KEY] ?: DEFAULT_VALUE
    }

// to retrieve data
fun getEmail(): Flow<String> =
    dataStore.secureMap(value, aes) { preference, encryptedValue ->
        preference[EMAIL_KEY] = encryptedValue
    }

License

License of this project is under Apache 2.0 license