diff options
author | Paul Frazee <pfrazee@gmail.com> | 2022-06-15 22:08:28 -0500 |
---|---|---|
committer | Paul Frazee <pfrazee@gmail.com> | 2022-06-15 22:08:28 -0500 |
commit | a56cae626abf6c553cd9756db875c8ab5f903879 (patch) | |
tree | 4c2c8ef9f00006a573959db84c8e3b037105a0bd /android/app/src/main/java/xyz/blueskyweb/pubsq/AppSecureRandomModule.java | |
parent | 2c73703d7d59bdd9a3e4b10c41e5099b8f92db1c (diff) | |
download | voidsky-a56cae626abf6c553cd9756db875c8ab5f903879.tar.zst |
Move the secure-random code into this project due to build issues with the module, which is no longer maintained
Diffstat (limited to 'android/app/src/main/java/xyz/blueskyweb/pubsq/AppSecureRandomModule.java')
-rw-r--r-- | android/app/src/main/java/xyz/blueskyweb/pubsq/AppSecureRandomModule.java | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/android/app/src/main/java/xyz/blueskyweb/pubsq/AppSecureRandomModule.java b/android/app/src/main/java/xyz/blueskyweb/pubsq/AppSecureRandomModule.java new file mode 100644 index 000000000..96887c36f --- /dev/null +++ b/android/app/src/main/java/xyz/blueskyweb/pubsq/AppSecureRandomModule.java @@ -0,0 +1,28 @@ +package xyz.blueskyweb.pubsq; + +import com.facebook.react.bridge.ReactApplicationContext; +import com.facebook.react.bridge.ReactContextBaseJavaModule; +import com.facebook.react.bridge.ReactMethod; +import com.facebook.react.bridge.Promise; + +import java.security.SecureRandom; +import android.util.Base64; + +public class AppSecureRandomModule extends ReactContextBaseJavaModule { + public AppSecureRandomModule(ReactApplicationContext context) { + super(context); + } + + @ReactMethod + public void generateSecureRandomAsBase64(int length, Promise promise) { + SecureRandom secureRandom = new SecureRandom(); + byte[] buffer = new byte[length]; + secureRandom.nextBytes(buffer); + promise.resolve(Base64.encodeToString(buffer, Base64.NO_WRAP)); + } + + @Override + public String getName() { + return "AppSecureRandomModule"; + } +} |