I took much of this from an example I found online years ago but I can't find the link just now. Here is some msdn info...
This allows you to store the key and vector as a string where you see fit, like web.config, sql, or a text file in a secret location.
Warning about Triple DES: It appears that AES is the current go to encryption standard, so keep that in mind before using 3DES :).
[TestMethod] public void TripleDESKeyVector() { var key = MyTripleDES.CreateNewKey(); var vector = MyTripleDES.CreateNewVector(); var tripleDes = new MyTripleDES(key: key, iv: vector); var myString = "Yo ho ho, triple des to go."; var encryptedVal = tripleDes.Encrypt(myString); var decryptedVal = tripleDes.Decrypt(encryptedVal); }
I updated the encrypt and decrypt with return HttpServerUtility.UrlTokenEncode(output) because I needed the encrypted value in a url and in browser DOM. Check out the Captha url!