Created
July 28, 2014 22:22
-
-
Save chase/3a4bb2fbbbe45163a725 to your computer and use it in GitHub Desktop.
UUID v5 calculator for email addresses
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'); | |
var nsURL = new Buffer([0x6b,0xa7,0xb8,0x11,0x9d,0xad,0x11,0xd1,0x80,0xb4,0x00,0xc0,0x4f,0xd4,0x30,0xc8]); | |
var emailUUID = function(email) { | |
var shasum = crypto.createHash('sha1'); | |
shasum.update(Buffer.concat([nsURL, new Buffer('mailto:'+email)])); | |
shasum=shasum.digest(); | |
var result = new Buffer(16); | |
shasum.copy(result, 0, 0, 16); | |
result.writeUInt16LE((result.readUInt16LE(6) & 0x0FFF) | (5 << 12), 6); | |
result.writeUInt8((result.readUInt8(8) & 0x3F) | 0x80, 6); | |
return result.slice(0,4).toString('hex') + | |
'-' + result.slice(4,6).toString('hex') + | |
'-' + result.slice(6,8).toString('hex') + | |
'-' + result.slice(8,10).toString('hex') + | |
'-' + result.slice(10).toString('hex') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment