private static string WindowsDeobfuscate(string value)
{
#if __MonoCS__
// This macro prevents compilation errors on Unix where ProtectedData does not exist.
throw new ApplicationException("Should never be reached");
#else
try
{
byte[] data = Convert.FromBase64String(value);
//Decrypt the data using DataProtectionScope.CurrentUser.
byte[] uncrypt = ProtectedData.Unprotect(data, GetCryptoKey(), DataProtectionScope.CurrentUser);
return System.Text.Encoding.UTF8.GetString(uncrypt);
}
catch (Exception e)
{
if (e is CryptographicException || e is FormatException)
{
Console.WriteLine("Your password is not obfuscated yet.");
Console.WriteLine("Using unobfuscated value directly might be deprecated soon, so please delete your local directories and recreate them. Thank you for your understanding.");
return value;
}
else
{
throw;
}
}
#endif
}