mirror of
https://github.com/gchq/CyberChef.git
synced 2024-11-16 08:58:30 +01:00
Merge branch 'bug/uuid' of https://github.com/artemisbot/CyberChef into artemisbot-bug/uuid
This commit is contained in:
commit
029c55fd53
1 changed files with 12 additions and 19 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
import crypto from "crypto";
|
||||||
/**
|
/**
|
||||||
* UUID operations.
|
* UUID operations.
|
||||||
*
|
*
|
||||||
|
@ -17,25 +18,17 @@ const UUID = {
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
runGenerateV4: function(input, args) {
|
runGenerateV4: function(input, args) {
|
||||||
if (window && typeof(window.crypto) !== "undefined" && typeof(window.crypto.getRandomValues) !== "undefined") {
|
const buf = new Uint32Array(4).map(() => {
|
||||||
let buf = new Uint32Array(4),
|
return crypto.randomBytes(4).readUInt32BE(0, true);
|
||||||
i = 0;
|
});
|
||||||
window.crypto.getRandomValues(buf);
|
let i = 0;
|
||||||
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
||||||
let r = (buf[i >> 3] >> ((i % 8) * 4)) & 0xf,
|
let r = (buf[i >> 3] >> ((i % 8) * 4)) & 0xf,
|
||||||
v = c === "x" ? r : (r & 0x3 | 0x8);
|
v = c === "x" ? r : (r & 0x3 | 0x8);
|
||||||
i++;
|
i++;
|
||||||
return v.toString(16);
|
return v.toString(16);
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
|
||||||
let r = Math.random() * 16 | 0,
|
|
||||||
v = c === "x" ? r : (r & 0x3 | 0x8);
|
|
||||||
return v.toString(16);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
},
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default UUID;
|
export default UUID;
|
||||||
|
|
Loading…
Reference in a new issue