c#MD5加密

#region MD5加密
        /// <summary>
        /// MD5加密
        /// </summary>
        /// <param name="stream">数据流</param>
        /// <returns>返回加密后的字符串</returns>
        public static string GetMD5(Stream stream)
        {
            MD5 md5 = new MD5CryptoServiceProvider();
            //Calculate MD5 Checksum
            byte[] data = md5.ComputeHash(stream);
            //convert to string
            StringBuilder sb = new StringBuilder();
            sb.Length = data.Length * 2;
            for (int i = 0; i < data.Length; i++)
            {
                sb[i * 2] = HEX_TABLE[data[i] >> 4];
                sb[i * 2 + 1] = HEX_TABLE[data[i] & 0xF];
            }
            md5.Clear();
            return sb.ToString();
        }

        /// <summary>
        /// MD5加密
        /// </summary>
        /// <param name="s">要加密的字符串</param>
        /// <returns>返回加密后的字符串</returns>
        public static string GetMD5(string s)
        {
            byte[] data = ASCIIEncoding.ASCII.GetBytes(s);
            MemoryStream stream = new MemoryStream(data);
            //stream.Write(data,0,data.Length);

            return GetMD5(stream);
        }
        #endregion

 

c#MD5加密

上一篇:win10 使用tracetcp.exe的错误问题解决(xjl456852原创)


下一篇:工控随笔_C#连接PLC_之_C#入门_06_流程控制