This repository has been archived by the owner on Nov 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
319 additions
and
314 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-12/"/> | ||
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/> | ||
<classpathentry kind="output" path="bin/default"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>android_</name> | ||
<name>android</name> | ||
<comment>Project android_ created by Buildship.</comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.buildship.core.gradleprojectbuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
<nature>org.eclipse.buildship.core.gradleprojectnature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
android/src/main/java/com/emeraldsanto/encryptedstorage/RNEncryptedStorageModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package com.emeraldsanto.encryptedstorage; | ||
|
||
import android.content.SharedPreferences; | ||
import android.content.res.Resources; | ||
import android.util.Log; | ||
|
||
import androidx.security.crypto.EncryptedSharedPreferences; | ||
import androidx.security.crypto.MasterKeys; | ||
|
||
import com.facebook.react.bridge.Promise; | ||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.bridge.ReactContext; | ||
import com.facebook.react.bridge.ReactContextBaseJavaModule; | ||
import com.facebook.react.bridge.ReactMethod; | ||
|
||
public class RNEncryptedStorageModule extends ReactContextBaseJavaModule { | ||
|
||
private static String NATIVE_MODULE_NAME = "RNEncryptedStorage"; | ||
private static String SHARED_PREFERENCES_FILENAME = "RN_ENCRYPTED_STORAGE_SHARED_PREF"; | ||
|
||
private SharedPreferences sharedPreferences; | ||
|
||
public RNEncryptedStorageModule(ReactApplicationContext context) { | ||
super(context); | ||
|
||
try { | ||
this.sharedPreferences = EncryptedSharedPreferences.create( | ||
RNEncryptedStorageModule.SHARED_PREFERENCES_FILENAME, | ||
MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC), | ||
context, | ||
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV, | ||
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM | ||
); | ||
} | ||
|
||
catch (Exception ex) { | ||
Log.w(RNEncryptedStorageModule.NATIVE_MODULE_NAME, String.format("Could not initialize SharedPreferences - %s", ex.getLocalizedMessage())); | ||
} | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return RNEncryptedStorageModule.NATIVE_MODULE_NAME; | ||
} | ||
|
||
@ReactMethod | ||
public void setItem(String key, String value, Promise promise) { | ||
if (this.sharedPreferences == null) { | ||
promise.reject(new NullPointerException("Could not initialize SharedPreferences")); | ||
return; | ||
} | ||
|
||
SharedPreferences.Editor editor = this.sharedPreferences.edit(); | ||
editor.putString(key, value); | ||
boolean saved = editor.commit(); | ||
|
||
if (saved) { | ||
promise.resolve(value); | ||
} | ||
|
||
else { | ||
promise.reject(new Exception(String.format("An error occured while saving %s", key))); | ||
} | ||
} | ||
|
||
@ReactMethod | ||
public void getItem(String key, Promise promise) { | ||
if (this.sharedPreferences == null) { | ||
promise.reject(new NullPointerException("Could not initialize SharedPreferences")); | ||
return; | ||
} | ||
|
||
String value = this.sharedPreferences.getString(key, null); | ||
|
||
promise.resolve(value); | ||
} | ||
|
||
@ReactMethod | ||
public void removeItem(String key, Promise promise) { | ||
if (this.sharedPreferences == null) { | ||
promise.reject(new NullPointerException("Could not initialize SharedPreferences")); | ||
return; | ||
} | ||
|
||
SharedPreferences.Editor editor = this.sharedPreferences.edit(); | ||
editor.remove(key); | ||
boolean saved = editor.commit(); | ||
|
||
if (saved) { | ||
promise.resolve(key); | ||
} | ||
|
||
else { | ||
promise.reject(new Exception(String.format("An error occured while removing %s", key))); | ||
} | ||
} | ||
} |
77 changes: 0 additions & 77 deletions
77
android/src/main/java/com/emeraldsanto/encryptedstorage/RNEncryptedStorageModule.kt
This file was deleted.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
android/src/main/java/com/emeraldsanto/encryptedstorage/RNEncryptedStoragePackage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.emeraldsanto.encryptedstorage; | ||
|
||
import com.facebook.react.ReactPackage; | ||
import com.facebook.react.bridge.NativeModule; | ||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.uimanager.ViewManager; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class RNEncryptedStoragePackage implements ReactPackage { | ||
|
||
@Override | ||
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) { | ||
return Collections.<NativeModule>singletonList(new RNEncryptedStorageModule(reactContext)); | ||
} | ||
|
||
@Override | ||
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) { | ||
return Collections.emptyList(); | ||
} | ||
} |
21 changes: 0 additions & 21 deletions
21
android/src/main/java/com/emeraldsanto/encryptedstorage/RNEncryptedStoragePackage.kt
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// RNEncryptedStorage.h | ||
// EncryptedStorage | ||
// | ||
// Created by Yanick Bélanger on 2020-02-27. | ||
// Copyright © 2020 Facebook. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import <React/RCTBridgeModule.h> | ||
|
||
@interface RNEncryptedStorage : NSObject <RCTBridgeModule> | ||
|
||
@end |
Oops, something went wrong.