vendredi 24 avril 2015

How to generate random key for HMACSHA256 signature calculation

I need to calculate a signature of some strings and was planning on doing this like this:

using (HMACSHA256 hmacSha256 = new HMACSHA256( <randombytes>))
{
         Byte[] dataToHmac = System.Text.Encoding.UTF8.GetBytes(sb.ToString());
         signature = Convert.ToBase64String(hmacSha256.ComputeHash(dataToHmac));
}

I am going to store the key together with my user data, but i am not sure if the randombytes can just be random or how to generate them in c#.

What is the proper way to generate random keys?




Aucun commentaire:

Enregistrer un commentaire