Example #1
0
        private static string decryptString(string source)
        {
            var result = source;

            if (!string.IsNullOrEmpty(source))
            {
                var    sourceBytes = Convert.FromBase64String(source);
                var    data        = (new SHA256Managed()).ComputeHash(Encoding.UTF8.GetBytes(BaseString));
                byte[] decryptionResult;
                using (var ms = new MemoryStream(sourceBytes))
                    using (var alg = new RijndaelManaged())
                    {
                        alg.IV  = data.Take(alg.BlockSize / 8).ToArray();
                        alg.Key = data.Take(32).ToArray();
                        using (var crstr = new CryptoStream(ms, alg.CreateDecryptor(), CryptoStreamMode.Read))
                            decryptionResult = crstr.AllBytes();
                    }
                result = Encoding.UTF8.GetString(decryptionResult);
            }
            return(result);
        }