Created
January 6, 2017 08:58
-
-
Save deathslocus/6b4e40f1bf65400c535ed43b20e634b9 to your computer and use it in GitHub Desktop.
Utility for creating version 3 UUID from name
This file contains 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
func nameUUIDFromBytes(name: String) -> NSUUID{ | |
let nameBytes = name.data(using: .utf8) | |
var digest : Data = (nameBytes?.md5())! | |
digest[6] &= 0x0F | |
digest[6] |= 0x30 | |
digest[8] &= 0x3F | |
digest[8] |= 0x80 | |
var arr : [UInt8] = [] | |
for i in digest { | |
arr.append(i) | |
} | |
return NSUUID(uuidBytes: arr) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I should note you need CryptoSwift for this to work https://github.com/krzyzanowskim/CryptoSwift