>using System.Security.Cryptography; > >class Program >{ >static void Main(string[] args) >{ >String plainText = "mypassword"; >String entropyText = "mykey"; >byte[] plainBytes = Encoding.Unicode.GetBytes(plainText); >byte[] entropyBytes = Encoding.Unicode.GetBytes(entropyText); > >//Errors occur here. >byte[] encryptedBytes = ProtectedData.Protect(plainBytes, entropyBytes, DataProtectionScope.CurrentUser); >} >} >>
using System; using System.Text; using System.Security.Cryptography; class Program { static void Main(string[] args) { String plainText = "mypassword"; String entropyText = "mykey"; byte[] plainBytes = Encoding.Unicode.GetBytes(plainText); byte[] entropyBytes = Encoding.Unicode.GetBytes(entropyText); //Errors occur here. byte[] encryptedBytes = ProtectedData.Protect(plainBytes, entropyBytes, DataProtectionScope.CurrentUser); PrintValues(encryptedBytes); byte[] decryptedBytes = ProtectedData.Unprotect(encryptedBytes, entropyBytes, DataProtectionScope.CurrentUser); Console.WriteLine(Encoding.Unicode.GetString(decryptedBytes)); } public static void PrintValues( Byte[] myArr ) { foreach ( Byte i in myArr ) { Console.Write( "\t{0}", i ); } Console.WriteLine(); } }Cetin