0

I'm trying to get a short unique ID for a machine. What I'm currently doing is this:

string mac = GetMacAddress();
mac = mac.Substring(2,2) + mac.Substring(6);
// We dont care about most of the vendor bit

SHA1Managed sha = new SHA1Managed();
string hash = Convert.ToBase64String(sha.ComputeHash(
                                     Encoding.Default.GetBytes(mac)));

_uniqueId = hash.Replace("=", string.Empty).Replace("+", string.Empty)
             .Replace("/", string.Empty).Remove(6);

 sha.Dispose();

Obviously it isn't ideal but is this ok? Is there a better portion of the SHA1 hash to use? Or does anyone have any better ideas?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
JoeS
  • 1,405
  • 17
  • 30
  • In order for us to improve your code you should tell us exactly what you aim for, is this an anti-copy mechanism? – Rodrigo Silva Dec 22 '13 at 18:16
  • Its not ideal to rely on a single piece of hardware. What if the nic is replaced or another one is added? Better to track three or more independent items and accept discrete changes. – Mattias Åslund Dec 22 '13 at 18:18
  • Unlike forum sites, we don't use "Thanks", or "Any help appreciated", or signatures on [so]. See "[Should 'Hi', 'thanks,' taglines, and salutations be removed from posts?](http://meta.stackexchange.com/questions/2950/should-hi-thanks-taglines-and-salutations-be-removed-from-posts). – John Saunders Dec 22 '13 at 18:22
  • Take a look at this SO question that gives you a good answer:http://stackoverflow.com/questions/2333149/how-to-fast-get-hardware-id-in-c – Mattias Åslund Dec 22 '13 at 18:39
  • Thanks for all of the comments. This is basically just so that we can identify client computers. Settled for a combination of a hash of the MAC and time since installation in the end. Have updated post. John: Ah I did wonder why my pleasentries kept getting deleted – JoeS Dec 22 '13 at 18:46

0 Answers0