MD5和SHA1加密

 //MD5特殊加密
        public static string MD51(string password)
        {
            string strResult = ""
            MD5 md5 = System.Security.Cryptography.MD5.Create();
            byte[] byteresult = md5.ComputeHash(Encoding.UTF8.GetBytes(password));
            for (int i = 0; i < byteresult.Length; i++)
            {
                strResult += byteresult[i].ToString();

            }
            return strResult;
        }

        public static string Get_MD5_Method1(string strSource)
        {
            //new
            MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
            //获取密文字节数组
            byte[] bytResult = md5.ComputeHash(System.Text.Encoding.Default.GetBytes(strSource));

            //转换成字符串,并取9到25位
           
            string strResult = BitConverter.ToString(bytResult, 4, 8);
            //转换成字符串,32位
            //string strResult = BitConverter.ToString(bytResult);

            //BitConverter转换出来的字符串会在每个字符中间产生一个分隔符,需要去除掉
            strResult = strResult.Replace("-""");
            return strResult;
        }
        //SHA1加密
        public static string EncryptPassword(string password) 
        {
            string s="";
            UnicodeEncoding encoding = new UnicodeEncoding();
            byte[] hashBytes = encoding.GetBytes(password);
            SHA1 sha1 = new SHA1CryptoServiceProvider();
            byte[] cryptPassWord = sha1.ComputeHash(hashBytes);
            for (int i = 0; i < cryptPassWord.Length; i++)
            {
                s += cryptPassWord[i].ToString();
            }
                return s;
        }
原文地址:https://www.cnblogs.com/houziwty/p/2215443.html