/// <summary> /// 3des加密字符串 /// </summary> /// <param name="text">要加密的字符串</param> /// <param name="key">密钥</param> /// <returns>加密后并经base64编码的字符串</returns> /// <remarks>静态方法,采用默认ascii编码</remarks> public static string Encrypt(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 DESEncrypt = DES.CreateEncryptor(); byte[] Buffer = ASCIIEncoding.UTF8.GetBytes(text); string pass = Base64Helper.ToBase64String(DESEncrypt.TransformFinalBlock (Buffer, 0, Buffer.Length)); return(pass); }//end method
public static string Base64Decode(string source) { byte[] barray = Base64Helper.FromBase64String(source); return(Encoding.Default.GetString(barray)); }
public static string Base64Encode(string source) { byte[] barray = Encoding.Default.GetBytes(source); return(Base64Helper.ToBase64String(barray)); }