MD5加密

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;

namespace MD5加密练习1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("请输入字符");
            string s = Console.ReadLine();
            string md5= GetMD5(s);
            Console.WriteLine(md5);
            Console.ReadKey();
        }
        public static string GetMD5(string strPwd)
        {
            MD5 md5 = new MD5CryptoServiceProvider();
            byte[] bPwd = Encoding.UTF8.GetBytes(strPwd);
            byte[] bMD5 = md5.ComputeHash(bPwd);
            md5.Clear();
            StringBuilder sbMD5Pwd = new StringBuilder();
            for (int i = 0; i < bMD5.Length; i++)
            {
                sbMD5Pwd.Append(bMD5[i].ToString("X2"));
            }
            return sbMD5Pwd.ToString();
        }
    }
}

posted @ 2019-03-04 20:15  崇尚技术  阅读(145)  评论(0编辑  收藏  举报