Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/a1573595/SecuritySharedPreferences
A small SharedPreferences wrapper and cryptographic android library power by Kotlin.
https://github.com/a1573595/SecuritySharedPreferences
aes android base64 keystore kotlin rsa security sharedpreferences
Last synced: about 2 months ago
JSON representation
A small SharedPreferences wrapper and cryptographic android library power by Kotlin.
- Host: GitHub
- URL: https://github.com/a1573595/SecuritySharedPreferences
- Owner: a1573595
- Created: 2020-10-10T12:20:25.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2021-10-30T09:00:42.000Z (almost 3 years ago)
- Last Synced: 2024-07-11T14:42:44.191Z (3 months ago)
- Topics: aes, android, base64, keystore, kotlin, rsa, security, sharedpreferences
- Language: Kotlin
- Homepage:
- Size: 188 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Security: securitysharedpreferences/.gitignore
Awesome Lists containing this project
- awesome-list - a1573595/SecuritySharedPreferences - A small SharedPreferences wrapper and cryptographic android library power by Kotlin. (Kotlin)
README
*Read this in other languages: [English](README.md), [δΈζ](README.zh-tw.md).*
# SecuritySharedPreferences
A small SharedPreferences wrapper and cryptographic android library power by Kotlin.β‘ Kotlin powered.
π Easy to use.
π Protect data (Android KeyStore + AES256 SIV / + AES256 GCM).
π§ͺ Support Unit test.
## Difference
Difference between the android SharedPreference and SecuritySharedPreferences library.
* SharedPreference
``````
* SecuritySharedPreferences
```AVQneV9aILgdLAT+OYJowJYWzeRktEj7gsttnTN4bLXMa690QKYnBWq1MuwnFpYAhjV/Gna2axuvqw==
```
## Supported Android Versions
- Android 5.1 Lollipop(API level 21) or higher.## Gradle
```groovy
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
``````groovy
dependencies {
implementation 'com.github.a1573595:SecuritySharedPreferences:2.0.3'
// Optional - Unit test
testImplementation 'junit:junit:4.13.2'
testImplementation 'androidx.arch.core:core-testing:2.1.0'
testImplementation 'androidx.test:core-ktx:1.4.0'
testImplementation 'androidx.test.ext:junit-ktx:1.1.3'
testImplementation 'org.robolectric:robolectric:4.6.1'
}
```## Usage
Define your SecuritySharedPreferences and add the parameters to be stored.
```kotlin
class DefaultPreferences(context: Context) :
SecuritySharedPreferences(context, context.packageName) {
// Add your stored parameter...
var userName by PreferencesData("Name", "Chien")var email by PreferencesData("Email", "")
var address by PreferencesData("Address", "")
var age by PreferencesData("Age", 25)
var height by PreferencesData("Height", 1.75f)
}
```Or you can customize the KeyStore alias, SharedPreferences name and mode.
```kotlin
class CustomPreferences(context: Context) :
SecuritySharedPreferences(context, "${context.packageName}.custom") {
// Add your stored parameter...
}
```Initialization SecuritySharedPreferences instance, easy to get and set stored value.
```kotlin
val preferencesManager = DefaultPreferences(this)// get value from SecuritySharedPreferences
val email = preferencesManager.email// save value into SecuritySharedPreferences
preferencesManager.email = "[email protected]"
```## Unit test
```kotlin
@RunWith(AndroidJUnit4::class)
class SecuritySharedPreferencesTest {
companion object {
@JvmStatic
@BeforeClass
fun beforeClass() {
FakeAndroidKeyStore.setup
}
}private val preferences: CustomPreferences =
CustomPreferences(ApplicationProvider.getApplicationContext())...
}
```## Reference
[AndroidKeyStore](https://github.com/joetsaitw/AndroidKeyStore)[Testing Jetpack Security with Robolectric](https://proandroiddev.com/testing-jetpack-security-with-robolectric-9f9cf2aa4f61)