Hi,
When creating the instance, the KEY and IV are generated for me.
RijndaelManaged myRijndael = new RijndaelManaged();
How can I store the Key in my database or web.config file?
And in what format?
Because I will have to load the key when trying to decrypt the encrypted string obviously.
thanks for your help, a little lost on this topic.
From stackoverflow
-
When storing binary as text (regardless if to a text file or a database field), the Base64 encoding is the way to go.
RijndaelManaged myRijndael = new RijndaelManaged(); // to Base64 string keyb64 = Convert.ToBase64String(myRijndael.Key); // reverse myRijndael.Key = Convert.FromBase64String(keyb64);
The Base64 string is safe to store anywhere you like.
Tomalak : "Why use it?" or "Why is it called like that?"?Tomalak : As to "Why use it?": It encodes binary bytes to a limited set of safe characters (out of the ASCII range). These characters do not get tampered with during mail transfer, are not affected by code page issues and Base64 is an agreed standard widely supported and easy to implement.Tomalak : As to "Why is it called like that?": Because it is _based_ on an alphabet of 64 characters.Will : You can also store your key as a byte array in the database, however its much more easy to support a base64 encoded string.Tomalak : No, there are not. That's the trick with Base64 - you can map 256 values to 64 at the expense of string length. Base64 simply needs more bytes than byte[]. See http://en.wikipedia.org/wiki/Base64Tomalak : BTW: If that answered your question, it would be nice if you accepted the answer. :-)
0 comments:
Post a Comment