Skip to content

Instantly share code, notes, and snippets.

@LinusU
Created April 30, 2014 12:32
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
UUID V5 Node.js
function uuid5(data) {
var out = crypto.createHash('sha1').update(data).digest();
out[8] = out[8] & 0x3f | 0xa0; // set variant
out[6] = out[6] & 0x0f | 0x50; // set version
var hex = out.toString('hex', 0, 16);
return [
hex.substring( 0, 8),
hex.substring( 8, 12),
hex.substring(12, 16),
hex.substring(16, 20),
hex.substring(20, 32)
].join('-');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment