|
5 | 5 | */
|
6 | 6 | var CryptoJS = CryptoJS || (function (Math, undefined) {
|
7 | 7 |
|
| 8 | + var crypto; |
| 9 | + |
| 10 | + // Native crypto from window (Browser) |
| 11 | + if (typeof window !== 'undefined' && window.crypto) { |
| 12 | + crypto = window.crypto; |
| 13 | + } |
| 14 | + |
| 15 | + // Native (experimental IE 11) crypto from window (Browser) |
| 16 | + if (!crypto && typeof window !== 'undefined' && window.msCrypto) { |
| 17 | + crypto = window.msCrypto; |
| 18 | + } |
| 19 | + |
| 20 | + // Native crypto from global (NodeJS) |
| 21 | + if (!crypto && typeof global !== 'undefined' && global.crypto) { |
| 22 | + crypto = global.crypto; |
| 23 | + } |
| 24 | + |
| 25 | + // Native crypto import via require (NodeJS) |
| 26 | + if (!crypto && typeof require === 'function') { |
| 27 | + try { |
| 28 | + crypto = require('crypto'); |
| 29 | + } catch (err) {} |
| 30 | + } |
| 31 | + |
8 | 32 | /*
|
9 | 33 | * Cryptographically secure pseudorandom number generator
|
10 | 34 | *
|
11 | 35 | * As Math.random() is cryptographically not safe to use
|
12 | 36 | */
|
13 | 37 | var cryptoSecureRandomInt = function () {
|
14 |
| - var crypto; |
15 |
| - |
16 |
| - // Native crypto from window (Browser) |
17 |
| - if (typeof window !== 'undefined' && window.crypto) { |
18 |
| - crypto = window.crypto; |
19 |
| - } |
20 |
| - |
21 |
| - // Native (experimental IE 11) crypto from window (Browser) |
22 |
| - if (!crypto && typeof window !== 'undefined' && window.msCrypto) { |
23 |
| - crypto = window.msCrypto; |
24 |
| - } |
25 |
| - |
26 |
| - // Native crypto from global (NodeJS) |
27 |
| - if (!crypto && typeof global !== 'undefined' && global.crypto) { |
28 |
| - crypto = global.crypto; |
29 |
| - } |
30 |
| - |
31 |
| - // Native crypto import via require (NodeJS) |
32 |
| - if (!crypto && typeof require === 'function') { |
33 |
| - try { |
34 |
| - crypto = require('crypto'); |
35 |
| - } catch (err) {} |
36 |
| - } |
37 |
| - |
38 | 38 | if (crypto) {
|
39 | 39 | // Use getRandomValues method (Browser)
|
40 | 40 | if (typeof crypto.getRandomValues === 'function') {
|
|
0 commit comments