Skip to main content

Posts

Showing posts with the label Cryptography

Using RNGCryptoServiceProvider and Character Masking

Uniquekey Generate Method Code : using System.Security.Cryptography; import the above class for using the code private string GetUniqueKey()   {   int maxSize  = 8 ;   int minSize = 5 ;   char[] chars = new char[62];   string a;   a = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";   chars = a.ToCharArray();   int size  = maxSize ;   byte[] data = new byte[1];   RNGCryptoServiceProvider  crypto = new RNGCryptoServiceProvider();   crypto.GetNonZeroBytes(data) ;   size =  maxSize ;   data = new byte[size];   crypto.GetNonZeroBytes(data);   StringBuilder result = new StringBuilder(size) ;   foreach(byte b in data ) { result.Append(chars[b % (chars.Length - 1)]); }    return result.ToString();   } Generation Method Time Taken Number of Generated Keys Number of Duplicate Keys...