Esempio n. 1
0
        }//end method

        /// <summary>
        /// 3des解密字符串
        /// </summary>
        /// <param name="text">要解密的字符串</param>
        /// <param name="key">密钥</param>
        /// <returns>解密后的字符串</returns>
        /// <exception cref="">密钥错误</exception>
        /// <remarks>静态方法,采用默认ascii编码</remarks>
        public static string Decrypt(string text, string key)
        {
            TripleDESCryptoServiceProvider DES = new
                                                 TripleDESCryptoServiceProvider();
            MD5CryptoServiceProvider hashMD5 = new MD5CryptoServiceProvider();

            DES.Key  = hashMD5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(key));
            DES.Mode = CipherMode.ECB;

            ICryptoTransform DESDecrypt = DES.CreateDecryptor();

            string result = "";

            try
            {
                byte[] Buffer = Base64Helper.FromBase64String(text);
                result = ASCIIEncoding.UTF8.GetString(DESDecrypt.TransformFinalBlock
                                                          (Buffer, 0, Buffer.Length));
            }
            catch
            {
                return(text);
            }

            return(result);
        }
Esempio n. 2
0
 public static string Base64Decode(string source)
 {
     byte[] barray = Base64Helper.FromBase64String(source);
     return(Encoding.Default.GetString(barray));
 }