Language: C#
Using managed Data Protection to encrypt and decrypt data
1: using System; 2: using System.Security.Cryptography; 3: 4: namespace ConsoleApplication1 5: { 6: class Program 7: { 8: static void Main(string[] args) 9: { 10: string PlainText = "Luciano Evaristo Guerche"; 11: byte[] PlainData = (new System.Text.ASCIIEncoding()).GetBytes(PlainText); 12: byte[] Entropy = new byte[] { 29, 63, 63, 48, 36, 41, 89, 81, 38, 18, 47, 51, 8, 91, 32, 21 }; 13: byte[] ProtectedData = System.Security.Cryptography.ProtectedData.Protect(PlainData, Entropy, DataProtectionScope.LocalMachine); 14: byte[] UnprotectedData = System.Security.Cryptography.ProtectedData.Unprotect(ProtectedData, Entropy, DataProtectionScope.LocalMachine); 15: 16: Console.WriteLine("Plain Text: {0}", PlainText); 17: Console.WriteLine(); 18: Console.WriteLine("Plain Data: 0x{0}", BitConverter.ToString(PlainData).Replace("-", "")); 19: Console.WriteLine(); 20: Console.WriteLine("Protected Data: 0x{0}", BitConverter.ToString(ProtectedData).Replace("-", "")); 21: Console.WriteLine(); 22: Console.WriteLine("Unprotected Data: 0x{0}", BitConverter.ToString(UnprotectedData).Replace("-", "")); 23: Console.WriteLine(); 24: Console.ReadKey(false); 25: } 26: } 27: }
Tags:
Report Abuse
Subscribe
Discuss
What's new
What is it
New Snippet
Recent Snippets
My Snippets
Web Code
Search

