// Decrypt the data and store in a byte array. byte[] originalData = Unprotect(encryptedSecret); Console.WriteLine("{0}The original data is:", Environment.NewLine); string str = Encoding.Default.GetString(originalData); Console.WriteLine("解密之后的密码: " + str); PrintValues(originalData); }
//加密方法 public static byte[] Protect(byte[] data) {
try {
// Encrypt the data using DataProtectionScope.CurrentUser. The result can be decrypted // only by the same current user. return ProtectedData.Protect(data, s_aditionalEntropy, DataProtectionScope.LocalMachine); } catch (CryptographicException e) {
Console.WriteLine("Data was not encrypted. An error occurred."); Console.WriteLine(e.ToString()); return null; } }
//解密方法 public static byte[] Unprotect(byte[] data) {
try {
//Decrypt the data using DataProtectionScope.CurrentUser. return ProtectedData.Unprotect(data, s_aditionalEntropy, DataProtectionScope.LocalMachine); } catch (CryptographicException e) {
Console.WriteLine("Data was not decrypted. An error occurred."); Console.WriteLine(e.ToString()); return null; } }
public static void PrintValues(Byte[] myArr) {
foreach (Byte i in myArr) {
Console.Write("\t{0}", i); } Console.WriteLine(); }