Generating cryptographically safe random numbers (Part 2)
Matt Hawley wrote a function for creating passwords which made me post this:
public
static
string
GenerateRandomPassword()
{
StringBuilder sb =
new
StringBuilder();
byte[] data =
new
byte[16];
new
RNGCryptoServiceProvider().GetBytes(data);
foreach (byte
b in data)
{
sb.Append(b.ToString("X2"));
}
return
sb.ToString();
}
RNGCryptoServiceProvider.GetBytes Method