private static string WindowsObfuscate(string value)
{
#if __MonoCS__
// This macro prevents compilation errors on Unix where ProtectedData does not exist.
return "Should never be reached";
#else
try
{
byte[] data = System.Text.Encoding.UTF8.GetBytes(value);
// Encrypt the data using DataProtectionScope.CurrentUser. The result can be decrypted
// only by the same current user.
byte[] crypt = ProtectedData.Protect(data, GetCryptoKey(), DataProtectionScope.CurrentUser);
return Convert.ToBase64String(crypt, Base64FormattingOptions.None);
}
catch (CryptographicException e)
{
Console.WriteLine("Data was not encrypted. An error occurred.");
Console.WriteLine(e.ToString());
return null;
}
#endif
}