Ground work for display layout support.
2 using System.Collections.Generic;
6 using System.Threading.Tasks;
8 namespace SharpDisplayManager
11 /// As per: http://weblogs.asp.net/jongalloway/encrypting-passwords-in-a-net-app-config-file
15 static byte[] entropy = System.Text.Encoding.Unicode.GetBytes("kd566slqfjls234895DFG743fqdlskj345SDFDepozwxc,n*ù^$^é");
17 public static string EncryptString(System.Security.SecureString input)
19 byte[] encryptedData = System.Security.Cryptography.ProtectedData.Protect(
20 System.Text.Encoding.Unicode.GetBytes(ToInsecureString(input)),
22 System.Security.Cryptography.DataProtectionScope.CurrentUser);
23 return Convert.ToBase64String(encryptedData);
26 public static SecureString DecryptString(string encryptedData)
30 byte[] decryptedData = System.Security.Cryptography.ProtectedData.Unprotect(
31 Convert.FromBase64String(encryptedData),
33 System.Security.Cryptography.DataProtectionScope.CurrentUser);
34 return ToSecureString(System.Text.Encoding.Unicode.GetString(decryptedData));
38 return new SecureString();
42 public static SecureString ToSecureString(string input)
44 SecureString secure = new SecureString();
45 foreach (char c in input)
49 secure.MakeReadOnly();
53 public static string ToInsecureString(SecureString input)
55 string returnValue = string.Empty;
56 IntPtr ptr = System.Runtime.InteropServices.Marshal.SecureStringToBSTR(input);
59 returnValue = System.Runtime.InteropServices.Marshal.PtrToStringBSTR(ptr);
63 System.Runtime.InteropServices.Marshal.ZeroFreeBSTR(ptr);