Skip to content

Latest commit

 

History

History
46 lines (34 loc) · 1.76 KB

README.md

File metadata and controls

46 lines (34 loc) · 1.76 KB

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