forked from mvayngrib/react-native-randombytes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RNRandomBytes.m
43 lines (34 loc) · 887 Bytes
/
RNRandomBytes.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//
// RNRandom.m
// randombytes
//
// Created by Mark Vayngrib on 10/13/15.
// Copyright (c) 2015 Facebook. All rights reserved.
//
#import "RNRandomBytes.h"
#import <React/RCTBridgeModule.h>
#import <React/RCTBridge.h>
@implementation RNRandomBytes
RCT_EXPORT_MODULE()
@synthesize bridge = _bridge;
RCT_EXPORT_METHOD(randomBytes:(NSUInteger)length
callback:(RCTResponseSenderBlock)callback)
{
callback(@[[NSNull null], [self randomBytes:length]]);
}
- (NSString *) randomBytes:(NSUInteger)length
{
NSMutableData* bytes = [NSMutableData dataWithLength:length];
SecRandomCopyBytes(kSecRandomDefault, length, [bytes mutableBytes]);
return [bytes base64EncodedStringWithOptions:0];
}
- (NSDictionary *)constantsToExport
{
return @{
@"seed": [self randomBytes:4096]
};
};
+ (BOOL)requiresMainQueueSetup {
return YES;
}
@end