├── .gitignore ├── .idea ├── codeStyles │ ├── Project.xml │ └── codeStyleConfig.xml └── runConfigurations.xml ├── .travis.yml ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── boomesh │ │ └── espsample │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── boomesh │ │ │ └── espsample │ │ │ └── MainActivity.kt │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── boomesh │ └── espsample │ └── ExampleUnitTest.kt ├── build.gradle ├── gradle.properties ├── gradle ├── common.gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── security ├── .gitignore ├── build.gradle ├── jacoco.gradle ├── proguard-rules.pro ├── publish.gradle └── src │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── boomesh │ │ │ └── security │ │ │ ├── common │ │ │ ├── BuildConfigUtil.kt │ │ │ ├── DataSerializeUtil.kt │ │ │ └── DateUtil.kt │ │ │ ├── di │ │ │ ├── CommonModule.kt │ │ │ ├── EncryptionModule.kt │ │ │ └── MainModule.kt │ │ │ ├── encrypt │ │ │ ├── KeyGeneratorSpecBuilder.kt │ │ │ └── securable │ │ │ │ ├── AesGcmNoPadding.kt │ │ │ │ ├── RsaEcbPKCS1Padding.kt │ │ │ │ ├── RsaWithDeprecatedAes.kt │ │ │ │ └── base │ │ │ │ ├── Decryptable.kt │ │ │ │ ├── Encryptable.kt │ │ │ │ └── Securable.kt │ │ │ └── preferences │ │ │ ├── EncryptedSharedPreferences.kt │ │ │ ├── SecurePrefs.kt │ │ │ └── editor │ │ │ ├── Editor.kt │ │ │ └── EditorListener.kt │ └── res │ │ └── values │ │ └── strings.xml │ └── test │ ├── java │ └── com │ │ └── boomesh │ │ └── security │ │ ├── common │ │ ├── BuildConfigUtilTest.kt │ │ └── DateUtilTest.kt │ │ ├── encrypt │ │ ├── KeyGeneratorSpecBuilderTest.kt │ │ ├── VersionTestable.kt │ │ └── securable │ │ │ ├── AesGcmNoPaddingTest.kt │ │ │ ├── RsaEcbPKCS1PaddingTest.kt │ │ │ └── RsaWithDeprecatedAesTest.kt │ │ ├── preferences │ │ └── editor │ │ │ ├── EditorTest.kt │ │ │ └── SecurePrefsTest.kt │ │ └── testhelpers │ │ └── MockMatchers.kt │ └── resources │ └── mockito-extensions │ └── org.mockito.plugins.MockMaker └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/java,kotlin,android,intellij,androidstudio 3 | # Edit at https://www.gitignore.io/?templates=java,kotlin,android,intellij,androidstudio 4 | 5 | ### Android ### 6 | # Built application files 7 | *.apk 8 | *.ap_ 9 | *.aab 10 | 11 | # Files for the ART/Dalvik VM 12 | *.dex 13 | 14 | # Java class files 15 | *.class 16 | 17 | # Generated files 18 | bin/ 19 | gen/ 20 | out/ 21 | 22 | # Gradle files 23 | .gradle/ 24 | build/ 25 | 26 | # Local configuration file (sdk path, etc) 27 | local.properties 28 | 29 | # Proguard folder generated by Eclipse 30 | proguard/ 31 | 32 | # Log Files 33 | *.log 34 | 35 | # Android Studio Navigation editor temp files 36 | .navigation/ 37 | 38 | # Android Studio captures folder 39 | captures/ 40 | 41 | # IntelliJ 42 | *.iml 43 | .idea/workspace.xml 44 | .idea/tasks.xml 45 | .idea/gradle.xml 46 | .idea/assetWizardSettings.xml 47 | .idea/dictionaries 48 | .idea/libraries 49 | .idea/caches 50 | # Android Studio 3 in .gitignore file. 51 | .idea/caches/build_file_checksums.ser 52 | .idea/modules.xml 53 | 54 | # Keystore files 55 | # Uncomment the following lines if you do not want to check your keystore files in. 56 | #*.jks 57 | #*.keystore 58 | 59 | # External native build folder generated in Android Studio 2.2 and later 60 | .externalNativeBuild 61 | 62 | # Google Services (e.g. APIs or Firebase) 63 | # google-services.json 64 | 65 | # Freeline 66 | freeline.py 67 | freeline/ 68 | freeline_project_description.json 69 | 70 | # fastlane 71 | fastlane/report.xml 72 | fastlane/Preview.html 73 | fastlane/screenshots 74 | fastlane/test_output 75 | fastlane/readme.md 76 | 77 | # Version control 78 | vcs.xml 79 | 80 | # lint 81 | lint/intermediates/ 82 | lint/generated/ 83 | lint/outputs/ 84 | lint/tmp/ 85 | # lint/reports/ 86 | 87 | ### Android Patch ### 88 | gen-external-apklibs 89 | output.json 90 | 91 | ### AndroidStudio ### 92 | # Covers files to be ignored for android development using Android Studio. 93 | 94 | # Built application files 95 | 96 | # Files for the ART/Dalvik VM 97 | 98 | # Java class files 99 | 100 | # Generated files 101 | 102 | # Gradle files 103 | .gradle 104 | 105 | # Signing files 106 | .signing/ 107 | 108 | # Local configuration file (sdk path, etc) 109 | 110 | # Proguard folder generated by Eclipse 111 | 112 | # Log Files 113 | 114 | # Android Studio 115 | /*/build/ 116 | /*/local.properties 117 | /*/out 118 | /*/*/build 119 | /*/*/production 120 | *.ipr 121 | *~ 122 | *.swp 123 | 124 | # Android Patch 125 | 126 | # External native build folder generated in Android Studio 2.2 and later 127 | 128 | # NDK 129 | obj/ 130 | 131 | # IntelliJ IDEA 132 | *.iws 133 | /out/ 134 | 135 | # User-specific configurations 136 | .idea/caches/ 137 | .idea/libraries/ 138 | .idea/shelf/ 139 | .idea/.name 140 | .idea/compiler.xml 141 | .idea/copyright/profiles_settings.xml 142 | .idea/encodings.xml 143 | .idea/misc.xml 144 | .idea/scopes/scope_settings.xml 145 | .idea/vcs.xml 146 | .idea/jsLibraryMappings.xml 147 | .idea/datasources.xml 148 | .idea/dataSources.ids 149 | .idea/sqlDataSources.xml 150 | .idea/dynamic.xml 151 | .idea/uiDesigner.xml 152 | 153 | # OS-specific files 154 | .DS_Store 155 | .DS_Store? 156 | ._* 157 | .Spotlight-V100 158 | .Trashes 159 | ehthumbs.db 160 | Thumbs.db 161 | 162 | # Legacy Eclipse project files 163 | .classpath 164 | .project 165 | .cproject 166 | .settings/ 167 | 168 | # Mobile Tools for Java (J2ME) 169 | .mtj.tmp/ 170 | 171 | # Package Files # 172 | *.war 173 | *.ear 174 | 175 | # virtual machine crash logs (Reference: http://www.java.com/en/download/help/error_hotspot.xml) 176 | hs_err_pid* 177 | 178 | ## Plugin-specific files: 179 | 180 | # mpeltonen/sbt-idea plugin 181 | .idea_modules/ 182 | 183 | # JIRA plugin 184 | atlassian-ide-plugin.xml 185 | 186 | # Mongo Explorer plugin 187 | .idea/mongoSettings.xml 188 | 189 | # Crashlytics plugin (for Android Studio and IntelliJ) 190 | com_crashlytics_export_strings.xml 191 | crashlytics.properties 192 | crashlytics-build.properties 193 | fabric.properties 194 | 195 | ### AndroidStudio Patch ### 196 | 197 | !/gradle/wrapper/gradle-wrapper.jar 198 | 199 | ### Intellij ### 200 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm 201 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 202 | 203 | # User-specific stuff 204 | .idea/**/workspace.xml 205 | .idea/**/tasks.xml 206 | .idea/**/usage.statistics.xml 207 | .idea/**/dictionaries 208 | .idea/**/shelf 209 | 210 | # Generated files 211 | .idea/**/contentModel.xml 212 | 213 | # Sensitive or high-churn files 214 | .idea/**/dataSources/ 215 | .idea/**/dataSources.ids 216 | .idea/**/dataSources.local.xml 217 | .idea/**/sqlDataSources.xml 218 | .idea/**/dynamic.xml 219 | .idea/**/uiDesigner.xml 220 | .idea/**/dbnavigator.xml 221 | 222 | # Gradle 223 | .idea/**/gradle.xml 224 | .idea/**/libraries 225 | 226 | # Gradle and Maven with auto-import 227 | # When using Gradle or Maven with auto-import, you should exclude module files, 228 | # since they will be recreated, and may cause churn. Uncomment if using 229 | # auto-import. 230 | # .idea/modules.xml 231 | # .idea/*.iml 232 | # .idea/modules 233 | 234 | # CMake 235 | cmake-build-*/ 236 | 237 | # Mongo Explorer plugin 238 | .idea/**/mongoSettings.xml 239 | 240 | # File-based project format 241 | 242 | # IntelliJ 243 | 244 | # mpeltonen/sbt-idea plugin 245 | 246 | # JIRA plugin 247 | 248 | # Cursive Clojure plugin 249 | .idea/replstate.xml 250 | 251 | # Crashlytics plugin (for Android Studio and IntelliJ) 252 | 253 | # Editor-based Rest Client 254 | .idea/httpRequests 255 | 256 | # Android studio 3.1+ serialized cache file 257 | 258 | # JetBrains templates 259 | **___jb_tmp___ 260 | 261 | ### Intellij Patch ### 262 | # Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 263 | 264 | # *.iml 265 | # modules.xml 266 | # .idea/misc.xml 267 | # *.ipr 268 | 269 | # Sonarlint plugin 270 | .idea/sonarlint 271 | 272 | ### Java ### 273 | # Compiled class file 274 | 275 | # Log file 276 | 277 | # BlueJ files 278 | *.ctxt 279 | 280 | # Mobile Tools for Java (J2ME) 281 | 282 | # Package Files # 283 | *.jar 284 | *.nar 285 | *.zip 286 | *.tar.gz 287 | *.rar 288 | 289 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 290 | 291 | ### Kotlin ### 292 | # Compiled class file 293 | 294 | # Log file 295 | 296 | # BlueJ files 297 | 298 | # Mobile Tools for Java (J2ME) 299 | 300 | # Package Files # 301 | 302 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 303 | 304 | # End of https://www.gitignore.io/api/java,kotlin,android,intellij,androidstudio -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 9 | 10 | 14 | 15 | 118 | 119 | 121 | 122 | -------------------------------------------------------------------------------- /.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: android 2 | dist: trusty 3 | 4 | android: 5 | components: 6 | # Uncomment the lines below if you want to 7 | # use the latest revision of Android SDK Tools 8 | - tools 9 | - platform-tools 10 | 11 | # The BuildTools version used by your project 12 | - build-tools-29.0.0 13 | 14 | # The SDK version used to compile your project 15 | - android-28 16 | 17 | # Additional components 18 | - extra-google-m2repository 19 | - extra-android-m2repository 20 | 21 | # Specify at least one system image, 22 | # if you need to run emulator(s) during your tests 23 | # - sys-img-x86-android-26 24 | # - sys-img-armeabi-v7a-android-17 25 | 26 | before_cache: 27 | - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock 28 | - rm -fr $HOME/.gradle/caches/*/plugin-resolution/ 29 | 30 | cache: 31 | directories: 32 | - $HOME/.gradle/caches/ 33 | - $HOME/.gradle/wrapper/ 34 | 35 | jobs: 36 | include: 37 | - stage: buildPullRequest 38 | if: (type IN (pull_request)) 39 | before_install: 40 | - mkdir "$ANDROID_HOME/licenses" || true 41 | - echo -e "\n24333f8a63b6825ea9c5514f83c2829b004d1fee\n8933bad161af4178b1185d1a37fbf41ea5269c55" > "$ANDROID_HOME/licenses/android-sdk-license" 42 | script: 43 | - ./gradlew clean :security:assembleDebug --stacktrace 44 | - ./gradlew :security:testDebugUnitTest --info 45 | - ./gradlew lint --stacktrace 46 | - ./gradlew :security:testDebugUnitTestCoverage 47 | - stage: buildDefault 48 | if: (type IN (push)) 49 | before_install: 50 | - mkdir "$ANDROID_HOME/licenses" || true 51 | - echo -e "\n24333f8a63b6825ea9c5514f83c2829b004d1fee\n8933bad161af4178b1185d1a37fbf41ea5269c55" > "$ANDROID_HOME/licenses/android-sdk-license" 52 | script: 53 | - ./gradlew clean :security:assemble --stacktrace 54 | - ./gradlew :security:testReleaseUnitTest --info 55 | after_success: 56 | - ./gradlew :security:testReleaseUnitTestCoverage :security:copyJacocoReport coveralls --info 57 | # deploy: 58 | # - provider: script 59 | # script: ./gradlew install bintrayUpload --info 60 | # skip_cleanup: true 61 | # on: 62 | # branch: master 63 | # tags: true 64 | # - provider: releases 65 | # api_key: 66 | # secure: "lwb8DJFAgSZzlrQ+NjsLSQqMju9vt/k63DQ24GW5lPTi5ZUcharrf+VexZmnxkYlIrrfYCpimqXw6GeSpi3hsys5pTT+0J53FjGvraT8g4X21teLhWlVLBeh5pIVw3VGWOcut/nJRcD4POnXTJV6kK/78qvUpddzrqYz72S9jGRt0kxDCxjYfcYBcx1OiFogy++nA9CTkMJkUsFC3asWwBSiZK2rc3TG5NIdrrlT6F0fOWELYxc1HT3W2P1tGi2f/V4G0XRop2Qe+zWNdlggkkQzw2slKrWbmf+nPK/TMCJLgXw2Uaru+P/SHW3Amg+thAibSJQFPQ1oJmUU7MuuCBAeu+Wyv//S35BjKhmQ94C0e8bSCJajGzR6/LjtOGVsAaJWLhq0F5k7v/UeGFb8fYDFDlbelzcQf2Df0ujBagDIadFzf+MQFnoG/B94lkPA/PSa9DFqZEPf4z1uTIRL0HL5ALFxRxpCyKaydmBvV4I9hHFZ2but1Pzx07ziP0JbQK7U1XdmPUHSePe/iLKz1NaXSwAChtwqsKTzww7vOCdlgjlU4x7uphu7HWk1m35hxBR5l7wPSp+jSw7gsmXmQlqPBJeNgGzGfBmH849dcV+PeVwYHiDsNzyqaeNCEir8UQBEe2ufTB+Irt+QvNswb35VHwXz2IhcrhRUzRdEs8Y=" 67 | # file_glob: true 68 | # file: 69 | # - 'armadillo/build/outputs/aar/*.aar' 70 | # skip_cleanup: true 71 | # on: 72 | # branch: master 73 | # tags: true -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2019 Sumesh 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # EncryptedSharedPreferences 2 | 3 | [![Download](https://api.bintray.com/packages/boomesh/security/EncryptedSharedPreferences/images/download.svg?version=1.0.0) ](https://bintray.com/boomesh/security/EncryptedSharedPreferences/1.0.0/link) 4 | [![Build Status](https://travis-ci.com/boomesh/EncryptedSharedPreferences.svg?branch=master)](https://travis-ci.com/boomesh/EncryptedSharedPreferences) 5 | [![Coverage Status](https://coveralls.io/repos/github/boomesh/EncryptedSharedPreferences/badge.svg?branch=master)](https://coveralls.io/github/boomesh/EncryptedSharedPreferences?branch=master) 6 | [![Maintainability](https://api.codeclimate.com/v1/badges/25bd5f7103896ae59066/maintainability)](https://codeclimate.com/github/boomesh/EncryptedSharedPreferences/maintainability) 7 | 8 | ## Purpose 9 | - this library gives you an out of the box solution for encrypting values in a Shared Preferences file via the Android Keystore 10 | - no need to worry about managing/generating keys in your app, just plug'n'play 11 | 12 | ## Requirements 13 | - Minimum of API 21 (Android Lollipop), [approximately 85% of all devices](https://developer.android.com/about/dashboards/index.html) 14 | - All the requirements of what the Android Keystore requires 15 | - uses `com.android.support.appcompat` (androidX is coming in the future!) 16 | 17 | ## Why use this library? 18 | - it's a very small library with very few dependencies 19 | - Comparatively [Armadillo](https://github.com/patrickfav/armadillo) is a really good library, and really feature rich. But you might not use all of those features, and it would bulk up your app 20 | - The AndroidX SDK Team will be releasing their [EncryptedSharedPreferences](https://developer.android.com/topic/security/data.md#classes-in-library), it's currently in [alpha](https://developer.android.com/jetpack/androidx/releases/security#1.0.0-alpha01), and I expect it to eventually replace this repo 21 | - the API for this library matches the API for AndroidX's library, so when it's ready you could switch to using this with minimal friction 22 | - [here's AndroidX's source](https://android.googlesource.com/platform/frameworks/support/+/refs/heads/androidx-master-dev/security/crypto/src/main/java/androidx/security/crypto/EncryptedSharedPreferences.java) 23 | 24 | ## What does it do 25 | - everything the [`android.content.SharedPreferences`](https://developer.android.com/reference/android/content/SharedPreferences) does with an added layer of encryption on top 26 | - the encryption under the hood relies on the Keystore (so your keys are _mostly_ managed by the OS keystore process1) 27 | 28 | ## Examples 29 | ### Initialize 30 | ```kotlin 31 | val prefs = EncryptedSharedPreferences.create(filename = "default", context) 32 | ``` 33 | 34 | ### Store a String 35 | ```kotlin 36 | val editor = prefs.edit() 37 | editor.putString("KEY", "value") 38 | editor.apply() 39 | ``` 40 | 41 | ### Get a String 42 | ```kotlin 43 | prefs.getString("KEY", "default value") 44 | ``` 45 | 46 | # Plans for the Future 47 | - replace support libs with androidx 48 | - introduce a mechanism for migrating from current shared prefs, to androidx shared prefs 49 | - perhaps some instrumentation tests? 50 | 51 | 52 | # Caveats 53 | 1. for below API 23 (Android Marshmallow), Symmetric Encryption is not supported out of the box. A key is generated, and stored in shared preferences (asymmetrically encrypted) -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | apply plugin: 'kotlin-android' 4 | 5 | apply plugin: 'kotlin-android-extensions' 6 | 7 | android { 8 | compileSdkVersion 28 9 | defaultConfig { 10 | applicationId "com.boomesh.espsample" 11 | minSdkVersion 21 12 | targetSdkVersion 28 13 | versionCode 1 14 | versionName "1.0" 15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 16 | } 17 | buildTypes { 18 | release { 19 | minifyEnabled true 20 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 21 | } 22 | } 23 | } 24 | 25 | dependencies { 26 | implementation fileTree(dir: 'libs', include: ['*.jar']) 27 | implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 28 | implementation 'com.android.support:appcompat-v7:28.0.0' 29 | implementation 'com.android.support.constraint:constraint-layout:1.1.3' 30 | 31 | implementation project(':security') 32 | 33 | testImplementation 'junit:junit:4.12' 34 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 35 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 36 | } 37 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/boomesh/espsample/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.boomesh.espsample 2 | 3 | import android.support.test.InstrumentationRegistry 4 | import android.support.test.runner.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getTargetContext() 22 | assertEquals("com.boomesh.espsample", appContext.packageName) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/boomesh/espsample/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.boomesh.espsample 2 | 3 | import android.content.SharedPreferences 4 | import android.os.Bundle 5 | import android.support.v7.app.AppCompatActivity 6 | import android.widget.Button 7 | import android.widget.EditText 8 | import android.widget.TextView 9 | import com.boomesh.security.preferences.EncryptedSharedPreferences 10 | 11 | class MainActivity : AppCompatActivity() { 12 | 13 | private lateinit var encryptText: EditText 14 | private lateinit var decryptText: TextView 15 | private lateinit var encryptInt: EditText 16 | private lateinit var decryptInt: TextView 17 | private lateinit var encryptLong: EditText 18 | private lateinit var decryptLong: TextView 19 | private lateinit var encryptFloat: EditText 20 | private lateinit var decryptFloat: TextView 21 | private lateinit var encryptStringSet: EditText 22 | private lateinit var decryptStringSet: TextView 23 | 24 | private lateinit var prefs: SharedPreferences 25 | 26 | companion object { 27 | private const val PREFS_KEY_TEXT = ".str" 28 | private const val PREFS_KEY_INT = ".int" 29 | private const val PREFS_KEY_LONG = ".long" 30 | private const val PREFS_KEY_FLOAT = ".float" 31 | private const val PREFS_KEY_STRSET = ".strset" 32 | } 33 | 34 | override fun onCreate(savedInstanceState: Bundle?) { 35 | super.onCreate(savedInstanceState) 36 | setContentView(R.layout.activity_main) 37 | 38 | encryptText = findViewById(R.id.encrypt_str_et) 39 | decryptText = findViewById(R.id.decrypt_str_tv) 40 | 41 | encryptInt = findViewById(R.id.encrypt_int_et) 42 | decryptInt = findViewById(R.id.decrypt_int_tv) 43 | 44 | encryptFloat = findViewById(R.id.encrypt_float_et) 45 | decryptFloat = findViewById(R.id.decrypt_float_tv) 46 | 47 | encryptLong = findViewById(R.id.encrypt_long_et) 48 | decryptLong = findViewById(R.id.decrypt_long_tv) 49 | 50 | encryptStringSet = findViewById(R.id.encrypt_strset_et) 51 | decryptStringSet = findViewById(R.id.decrypt_strset_tv) 52 | 53 | prefs = EncryptedSharedPreferences.create(applicationContext) 54 | } 55 | 56 | override fun onPostCreate(savedInstanceState: Bundle?) { 57 | super.onPostCreate(savedInstanceState) 58 | findViewById