Function for Creating Random key

Posted by SurajRane under C# category on | Views : 2222
Code for creating Key using Random numbers and alphabets.
You Can Find RNGCryptoServiceProvider class in below namespace.


public static string CreateKey(int length)
byte[] random = new byte[length / 2];
RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
StringBuilder Key = new StringBuilder(length);
for (int i = 0; i < random.Length; i++)
Key.Append(String.Format("{0:X2}", random[i]));
return Key.ToString();

Comments or Responses

Posted by: Raja on: 4/14/2010 Level:Starter | Status: [Member]
Which namespace "RNGCryptoServiceProvider " class contains? Can you please update your code with the namespace as well?

Thank you

Login to post response