|
|
@ -1,11 +1,20 @@ |
|
|
|
import 'react-native-get-random-values'; |
|
|
|
|
|
|
|
export function generateKey() { |
|
|
|
let result = []; |
|
|
|
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; |
|
|
|
let charactersLength = characters.length; |
|
|
|
|
|
|
|
let uintArray = new Uint8Array(64); |
|
|
|
let newKey = crypto.getRandomValues(uintArray); |
|
|
|
|
|
|
|
for (let i = 0; i < 64; i++) { |
|
|
|
let newCharIndex = newKey[i]; |
|
|
|
while(newCharIndex > charactersLength){ |
|
|
|
newCharIndex -= charactersLength; |
|
|
|
} |
|
|
|
result.push( |
|
|
|
characters.charAt(Math.floor(Math.random() * charactersLength)), |
|
|
|
characters.charAt(newCharIndex), |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|