-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.ts
More file actions
24 lines (24 loc) · 884 Bytes
/
Copy pathindex.ts
File metadata and controls
24 lines (24 loc) · 884 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { isIOS, isAndroid } from "platform";
let Buffer = require('buffer/').Buffer;
import { bcrypt } from "./bcrypt";
if (isIOS) {
// security
let randomBytes = (length) => {
let bytes = NSMutableData.dataWithLength(length);
SecRandomCopyBytes(null, length, <any>bytes.mutableBytes);
let buf = new Buffer(bytes.base64EncodedStringWithOptions(0), 'base64');
return buf;
};
bcrypt.setRandomFallback(randomBytes);
} else if (isAndroid) {
let randomBytes = (length) => {
let output = Array.create("byte", length);
new java.security.SecureRandom().nextBytes(output);
let buf = new Buffer(android.util.Base64.encodeToString(output, android.util.Base64.DEFAULT), 'base64');
return buf;
};
bcrypt.setRandomFallback(randomBytes);
} else {
throw "unknown platform execution";
}
export { bcrypt };