Created
August 5, 2011 17:11
-
-
Save vade/1128002 to your computer and use it in GitHub Desktop.
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
// Return the MAC address of this host, obfuscated for privacy. | |
// The result may be used as an ID which is unique to this host. | |
+ (NSString *)obfuscatedMACAddress | |
{ | |
NSString *address = [NSString MACAddress]; | |
if (!address) return nil; | |
const char *s = [address UTF8String]; | |
MD5_CTX c; | |
MD5_Init(&c); | |
MD5_Update(&c, s, strlen(s) ); | |
unsigned char hash[16]; | |
MD5_Final(hash, &c); | |
UInt32 *hash32 = (UInt32*)hash; | |
NSString *result = [NSString stringWithFormat:@"%04x%04x%04x%04x", | |
hash32[0], hash32[1], hash32[2], hash32[3] ]; | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment