Skip to content

Get Started

Requirements

  • encrypted-storage
    • Minimum API 23
  • fake-keystore
    • Minimum API 16

Implementation: Production

  • In your App module’s build.gradle file, add the following to the dependencies block:

    implementation 'io.matthewnelson.encrypted-storage:encrypted-storage:2.0.1'
    

  • Instantiation

    // Unencrypted Prefs
    val prefs = Prefs.createUnencrypted("MyClearTextPrefs", context)
    
    // Encrypted Prefs
    val encryptedPrefs = Prefs.createEncrypted("MyEncryptedPrefs", context)
    
    // Encrypted File
    val encryptedFile = EFile.createEncrypted(File("${context.filesDir.absolutePath}/MyEncryptedFile"), context)
    

Implementation: Testing

  • In your App module’s build.gradle file, add the following to the dependencies block:

    testImplementation 'io.matthewnelson.encrypted-storage:fake-keystore:2.0.1'
    

  • Add to your unit test the following:

    companion object {
        @JvmStatic
        @BeforeClass
        fun beforeClass() {
            FakeAndroidKeyStore.setup
        }
    }
    

Info

Special thanks to Matthew Dolan!
See his Medium article regarding unit testing with Jetpack Security here