mirror of
https://github.com/status-im/react-native-randombytes.git
synced 2026-08-30 18:41:15 +00:00
moved android implementation from /app to /android, rnpm link did not find the android implementation from app -directory.
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package com.bitgo.randombytes;
|
||||
|
||||
import com.facebook.react.bridge.ReactMethod;
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.bridge.Callback;
|
||||
|
||||
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
|
||||
import android.util.Base64;
|
||||
|
||||
class RandomBytesModule extends ReactContextBaseJavaModule {
|
||||
|
||||
public RandomBytesModule(ReactApplicationContext reactContext) {
|
||||
super(reactContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "RNRandomBytes";
|
||||
}
|
||||
@ReactMethod
|
||||
public void randomBytes(int size, Callback success) {
|
||||
SecureRandom sr = new SecureRandom();
|
||||
byte[] output = new byte[size];
|
||||
sr.nextBytes(output);
|
||||
String string = Base64.encodeToString(output, Base64.DEFAULT);
|
||||
success.invoke(null, string);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user