ARUP.IssueTracker.Classes.DataProtector.DecryptData C# (CSharp) Метод

DecryptData() публичный статический Метод

Decrypts a string using the DPAPI.
public static DecryptData ( string stringToDecrypt ) : string
stringToDecrypt string The string to decrypt.
Результат string
        public static string DecryptData(string stringToDecrypt)
        {
            if (!string.IsNullOrWhiteSpace(stringToDecrypt) && IsBase64String(stringToDecrypt))
            {
                try
                {
                    byte[] decryptedData = ProtectedData.Unprotect(Convert.FromBase64String(stringToDecrypt), Encoding.Unicode.GetBytes(EntropyValue), DataProtectionScope.LocalMachine);
                    return Encoding.Unicode.GetString(decryptedData);
                }
                catch
                {
                    
                }
            }
            return string.Empty;
        }
        public static bool IsBase64String(this string s)

Usage Example

Пример #1
0
        // For using in the Settings window only
        public static List <JiraAccount> GetAllJiraAccounts()
        {
            try
            {
                Configuration config = GetConfig();

                if (config == null)
                {
                    return(null);
                }

                List <JiraAccount> allAccounts = new List <JiraAccount>();
                foreach (string key in config.AppSettings.Settings.AllKeys)
                {
                    if (key.StartsWith("jiraaccount_"))
                    {
                        try
                        {
                            JiraAccount ac = SimpleJson.DeserializeObject <JiraAccount>(config.AppSettings.Settings[key].Value);
                            allAccounts.Add(ac);
                        }
                        catch (Exception ex)
                        {
                            allAccounts.Add(new JiraAccount()
                            {
                                active = false, jiraserver = string.Empty, username = string.Empty, password = string.Empty, guidfield = string.Empty, savedTime = (long)DateTime.Now.Subtract(new DateTime(1970, 1, 1)).TotalSeconds
                            });
                        }
                    }
                }

                // Compatibility for old version
                if (allAccounts.Count == 0)
                {
                    JiraAccount ac = new JiraAccount()
                    {
                        active = true, jiraserver = Get("jiraserver"), username = Get("username"), password = Get("password"), guidfield = Get("guidfield"), savedTime = (long)DateTime.Now.Subtract(new DateTime(1970, 1, 1)).TotalSeconds
                    };
                    // force to get a new config object to avoid conflict
                    config = GetConfig();

                    allAccounts.Add(ac);
                    string key   = "jiraaccount_" + Convert.ToInt32(DateTime.UtcNow.AddHours(8).Subtract(new DateTime(1970, 1, 1)).TotalSeconds);
                    string value = SimpleJson.SerializeObject(ac);
                    config.AppSettings.Settings.Add(key, value);
                    config.Save(ConfigurationSaveMode.Modified);
                }

                // Decrypt passwords
                allAccounts.ForEach(ac => ac.password = DataProtector.DecryptData(ac.password));

                return(allAccounts);
            }
            catch (Exception ex)
            {
                MessageBox.Show("exception: " + ex);
                return(null);
            }
        }
All Usage Examples Of ARUP.IssueTracker.Classes.DataProtector::DecryptData