winform的md5加密

/// <summary>
        /// Md5加密的方法
        /// </summary>
        /// <param name="code">几位加密</param>
        /// <param name="str"></param>
        /// <returns></returns>
        private string GetMd5(int code, string str)
        {
            string strmd5 = "";
            byte[] result = Encoding.Default.GetBytes(str);    //tbPass为输入密码的文本框
            MD5 md5 = new MD5CryptoServiceProvider();
            byte[] output = md5.ComputeHash(result);
            string md5str = BitConverter.ToString(output).Replace("-", "");

            if (code == 16) //16位MD5加密(取32位加密的9~25字符) 
            {
                strmd5 = md5str.Substring(8, 16);
            }
            if (code == 32) //32位加密 
            {
                strmd5 = md5str;
            }
            return strmd5;
        }

  

posted @ 2013-04-10 12:09  小锋神  阅读(1400)  评论(0编辑  收藏  举报