Decrypt() static private method

static private Decrypt ( string cipherText ) : string
cipherText string
return string
Exemplo n.º 1
0
        public T DeSerialize(string encryptedString)
        {
            T obj;

            try
            {
                var text = DataEncryption.Decrypt(encryptedString);
                obj = JsonConvert.DeserializeObject <T>(text);
            }
            catch (Exception)
            {
                obj = new T();
            }

            return(obj);
        }
Exemplo n.º 2
0
        private T DeSerialize(string encryptedString, int retryCount)
        {
            try
            {
                var text = DataEncryption.Decrypt(encryptedString);
                return(JsonConvert.DeserializeObject <T>(text));
            }
            catch (Exception)
            {
                if (retryCount >= 3)
                {
                    return(new T());
                }

                Thread.Sleep(100);
                return(DeSerialize(encryptedString, retryCount + 1));
            }
        }
Exemplo n.º 3
0
        private T DeSerialize(string fileToUse, int retryCount, int backupNumber)
        {
            if (fileToUse == null)
            {
                throw new SerializerError("No Save Path");
            }

            if (!File.Exists(fileToUse))
            {
                return(new T());
            }

            singleThreadMutex.WaitOne();

            try
            {
                var encryptedString = File.ReadAllText(fileToUse);
                var text            = DataEncryption.Decrypt(encryptedString, encryptionPassPhrase);
                if (string.IsNullOrWhiteSpace(text))
                {
                    throw new Exception("String in file is null or blank");
                }
                return(JsonConvert.DeserializeObject <T>(text));
            }
            catch (Exception ex)
            {
                if (retryCount >= 3)
                {
                    File.WriteAllText(Path.Combine(errorDirectory, $"DeSerializeFile_{DateTime.UtcNow:yyyy-MM-dd_hh-mm-ss}_{Guid.NewGuid()}.log"), ex.ToString());
                    var nextFile = backupNumber == 0 ? $"{backupPath}.bak" : $"{backupPath}.{backupNumber}.bak";
                    return(DeSerialize(nextFile, 0, backupNumber + 1));
                }

                Thread.Sleep(200);
                return(DeSerialize(fileToUse, retryCount + 1, backupNumber));
            }
            finally
            {
                singleThreadMutex.ReleaseMutex();
            }
        }
        internal static List <IdleTimer> DeSerialize()
        {
            List <IdleTimer> timers;

            if (File.Exists(SavePath))
            {
                try
                {
                    var text = DataEncryption.Decrypt(File.ReadAllText(SavePath));
                    timers = JsonConvert.DeserializeObject <List <IdleTimer> >(text);
                }
                catch (Exception)
                {
                    timers = new List <IdleTimer>();
                }
            }
            else
            {
                timers = new List <IdleTimer>();
            }

            return(timers);
        }
        internal static AppSettings DeSerialize()
        {
            AppSettings appSettings;

            if (File.Exists(SavePath))
            {
                try
                {
                    var text = DataEncryption.Decrypt(File.ReadAllText(SavePath));
                    appSettings = JsonConvert.DeserializeObject <AppSettings>(text);
                }
                catch (Exception)
                {
                    appSettings = new AppSettings();
                }
            }
            else
            {
                appSettings = new AppSettings();
            }

            return(appSettings);
        }
Exemplo n.º 6
0
        internal static JiraConnectionSettings DeSerialize()
        {
            JiraConnectionSettings jiraConnectionSettings;

            if (File.Exists(SavePath))
            {
                try
                {
                    var text = DataEncryption.Decrypt(File.ReadAllText(SavePath));
                    jiraConnectionSettings = JsonConvert.DeserializeObject <JiraConnectionSettings>(text);
                }
                catch (Exception)
                {
                    jiraConnectionSettings = new JiraConnectionSettings();
                }
            }
            else
            {
                jiraConnectionSettings = new JiraConnectionSettings();
            }

            return(jiraConnectionSettings);
        }