Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

when i declare the preference datastore as it is on the documentation, it says "no value passed for encryptionOptions" #12

Closed
RhymezxCode opened this issue Dec 10, 2022 · 4 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@RhymezxCode
Copy link

 val dataStore = getMasterKey(context)?.let {
                PreferenceDataStoreFactory.createEncrypted {
                    EncryptedFile(
                        context,
                        context.dataStoreFile(prefName!!),
                        masterKey = it
                    )
                }
            }
@RhymezxCode
Copy link
Author

   val aead = AndroidKeysetManager.Builder()
                .withSharedPref(context, "master_keyset", "master_key_preference")
                .withKeyTemplate(KeyTemplates.get("AES256_GCM"))
                .withMasterKeyUri("android-keystore://master_key")
                .build()
                .keysetHandle
                .getPrimitive(Aead::class.java)
            
            val dataStore = PreferenceDataStoreFactory.createEncrypted(
                encryptionOptions = {
                    // Specify fallback Aead to make it possible to decrypt data encrypted with it
                    fallbackAead = aead
                }
            ) {
                EncryptedFile.Builder(
                    context.dataStoreFile(prefName!!), // Keep the same file
                    context,
                    MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC),
                    EncryptedFile.FileEncryptionScheme.AES256_GCM_HKDF_4KB
                ).build()
            }

This option works, but i previously didn't use the library before.

If there is a better way, please explain to me

@osipxd
Copy link
Owner

osipxd commented Dec 10, 2022

Oh. I see there is a bug that PreferenceDataStoreFactory.createEncrypted has no default value for the encryptionOptions parameter. I'll fix it in the nexts version, but for now you can pass empty lambda as a workaround

PreferenceDataStoreFactory.createEncrypted {
    EncryptedFile(
        context,
        context.dataStoreFile(prefName!!),
        masterKey = it,
        // TODO: Remove this parameter when issue in encrypted-datastore will be fixed
        //  https://github.com/osipxd/encrypted-datastore/issues/12
        encryptionOptions = {} 
    )
}

@osipxd osipxd self-assigned this Dec 10, 2022
@osipxd osipxd added the bug Something isn't working label Dec 10, 2022
@osipxd osipxd added this to the Next milestone Dec 10, 2022
@osipxd osipxd closed this as completed in d24ae50 Dec 10, 2022
@RhymezxCode
Copy link
Author

Alright thanks

@osipxd
Copy link
Owner

osipxd commented Dec 20, 2022

Fixed in 1.0.0-alpha04

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants