[Mono-list] More on Guids. A sample
Miguel de Icaza
miguel@ximian.com
19 Sep 2001 20:40:28 -0400
------- Start of forwarded message -------
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Message-ID: <7DC0658D67A52C4B9697851D46A5A7A9027F18@oak.webappdesign.com>
Date: Tue, 18 Sep 2001 20:25:16 -0400
Reply-To: dotnet discussion <DOTNET@DISCUSS.DEVELOP.COM>
From: John Lam <jlam@IUNKNOWN.COM>
Subject: Re: [DOTNET] Guid.NewGuid()
To: DOTNET@DISCUSS.DEVELOP.COM
Content-Transfer-Encoding: 8bit
Here's a sample piece of code. I think it works, but I just typed it in
without compiling it ... ;)
-John
private System.Guid GimmeAGuid()
{
byte[] data = new byte[ 16 ]; // 16 bytes = 128 bits
System.Security.Cryptography.RNGCryptoServiceProvider rng = new
System.Security.Cryptography.RNGCryptoServiceProvider();
rng.GetBytes( data );
return new System.Guid( data );
}
-----Original Message-----
From: Dean Cleaver [mailto:deanc@NETTECH.CO.NZ]
Sent: Tuesday, September 18, 2001 8:24 PM
To: DOTNET@DISCUSS.DEVELOP.COM
Subject: Re: [DOTNET] Guid.NewGuid()
John,
Are you able to elaborate more on this call you use to generate GUIDS?
Dino
-----Original Message-----
From: dotnet discussion [mailto:DOTNET@DISCUSS.DEVELOP.COM] On Behalf Of
John Lam
Sent: Wednesday, 19 September 2001 12:19
To: DOTNET@DISCUSS.DEVELOP.COM
Subject: Re: [DOTNET] Guid.NewGuid()
Jason, we know that CoCreateGuid() thunks to CryptGenRandom() in the
case of Win2K and newer boxes. However, Guids are generated in .NET via
a call to the Guid.CompleteGuid() member function, which is an
internalcall function. Now since the implementation details of these
aren't known (do you know what DLL implements the internalcall
functions?) I guess we can *assume* that it calls CoCreateGuid() under
the covers.
But what if it doesn't? Personally, I'm rather paranoid about my Guids
(especially if you use them as uniqueidentifiers in SQL server), so I
call RNGCryptoServiceProvider.GetBytes() to generate my Guids.
-John
-----Original Message-----
From: Jason Whittington [mailto:jasonw@DEVELOP.COM]
Sent: Tuesday, September 18, 2001 5:14 PM
To: DOTNET@DISCUSS.DEVELOP.COM
Subject: Re: [DOTNET] Guid.NewGuid()
> > I believe this is a hash of the machine's current time stamp,
> > and the MAC address of the network card of the machine, so
> > can I assume that Guid.NewGuid() will genereate a unique
> > value even accross machines??
It used to be. Guid.NewGuid() internally winds up just calling
the Win32 function CryptGenRandom() on w2k and newer boxes.
Jason
You can read messages from the DOTNET archive, unsubscribe from DOTNET,
or
subscribe to other DevelopMentor lists at http://discuss.develop.com.
You can read messages from the DOTNET archive, unsubscribe from DOTNET,
or
subscribe to other DevelopMentor lists at http://discuss.develop.com.
---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.281 / Virus Database: 149 - Release Date: 18/09/2001
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.281 / Virus Database: 149 - Release Date: 18/09/2001
You can read messages from the DOTNET archive, unsubscribe from DOTNET,
or
subscribe to other DevelopMentor lists at http://discuss.develop.com.
You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.
------- End of forwarded message -------