This repository was archived by the owner on May 2, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +14
-19
lines changed Expand file tree Collapse file tree 3 files changed +14
-19
lines changed Original file line number Diff line number Diff line change @@ -165,12 +165,11 @@ class AESKeyField extends Component {
165
165
}
166
166
167
167
randomKey = ( ) => {
168
- let key = "" ;
169
- const possible = 'abcdef0123456789' ;
168
+ let cryptoObj = window . crypto || window . msCrypto ;
169
+ let b = new Uint8Array ( 16 ) ;
170
+ cryptoObj . getRandomValues ( b ) ;
170
171
171
- for ( let i = 0 ; i < 32 ; i ++ ) {
172
- key += possible . charAt ( Math . floor ( Math . random ( ) * possible . length ) ) ;
173
- }
172
+ let key = Buffer . from ( b ) . toString ( 'hex' ) ;
174
173
this . setState ( {
175
174
value : key ,
176
175
} ) ;
Original file line number Diff line number Diff line change @@ -76,12 +76,11 @@ class EUI64Field extends Component {
76
76
}
77
77
78
78
randomKey = ( ) => {
79
- let key = "" ;
80
- const possible = 'abcdef0123456789' ;
79
+ let cryptoObj = window . crypto || window . msCrypto ;
80
+ let b = new Uint8Array ( 8 ) ;
81
+ cryptoObj . getRandomValues ( b ) ;
81
82
82
- for ( let i = 0 ; i < 16 ; i ++ ) {
83
- key += possible . charAt ( Math . floor ( Math . random ( ) * possible . length ) ) ;
84
- }
83
+ let key = Buffer . from ( b ) . toString ( 'hex' ) ;
85
84
this . setState ( {
86
85
value : key ,
87
86
} ) ;
Original file line number Diff line number Diff line change @@ -46,22 +46,19 @@ class MulticastGroupForm extends FormComponent {
46
46
}
47
47
48
48
getRandomKey ( len ) {
49
- let key = "" ;
50
- const possible = 'abcdef0123456789' ;
49
+ let cryptoObj = window . crypto || window . msCrypto ;
50
+ let b = new Uint8Array ( len ) ;
51
+ cryptoObj . getRandomValues ( b ) ;
51
52
52
- for ( let i = 0 ; i < len ; i ++ ) {
53
- key += possible . charAt ( Math . floor ( Math . random ( ) * possible . length ) ) ;
54
- }
55
-
56
- return key ;
53
+ return Buffer . from ( b ) . toString ( 'hex' ) ;
57
54
}
58
55
59
56
getRandomMcAddr = ( cb ) => {
60
- cb ( this . getRandomKey ( 8 ) ) ;
57
+ cb ( this . getRandomKey ( 4 ) ) ;
61
58
}
62
59
63
60
getRandomSessionKey = ( cb ) => {
64
- cb ( this . getRandomKey ( 32 ) ) ;
61
+ cb ( this . getRandomKey ( 16 ) ) ;
65
62
}
66
63
67
64
You can’t perform that action at this time.
0 commit comments