mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-04-19 21:42:24 +00:00
chore: use crypto.randomUUID()
for generating UUIDv4
This commit is contained in:
parent
a45e9de472
commit
64fa0e97a3
1 changed files with 1 additions and 8 deletions
|
@ -126,14 +126,7 @@ class RandomUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
static randomUUID() {
|
static randomUUID() {
|
||||||
const template = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
|
return window.crypto.randomUUID()
|
||||||
return template.replace(/[xy]/g, function (c) {
|
|
||||||
const randomValues = new Uint8Array(1);
|
|
||||||
crypto.getRandomValues(randomValues);
|
|
||||||
let randomValue = randomValues[0] % 16;
|
|
||||||
let calculatedValue = (c === 'x') ? randomValue : (randomValue & 0x3 | 0x8);
|
|
||||||
return calculatedValue.toString(16);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static randomShadowsocksPassword() {
|
static randomShadowsocksPassword() {
|
||||||
|
|
Loading…
Reference in a new issue