Created
January 8, 2014 21:52
-
-
Save jed/8325181 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var crypto = require("crypto") | |
module.exports = function() { | |
var bytes = crypto.randomBytes(16) | |
bytes[6] &= 0x0f // 0000xxxx | |
bytes[6] += 0x40 // 0100xxxx | |
bytes[8] &= 0x3f // 00xxxxxx | |
bytes[8] += 0x80 // 10xxxxxx | |
return [0, 4, 6, 8, 10].map(map).join("-") | |
function map(len, i, arr) { | |
return bytes.slice(len, arr[i + 1]).toString("hex") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment