实现效果:

  使用MD5加密字符串_编程

实现代码:

static void Main(string[] args)
        {
            Console.WriteLine("Enter a string to MD5 encryption...\n");
            while (true)
            {
                Console.WriteLine(GetMD5(Console.ReadLine()));   
            }
        }
        static string GetMD5(string str)
        {
            byte[] bts1 = Encoding.Default.GetBytes(str);
            MD5 md5 = MD5.Create();
            StringBuilder result = new StringBuilder();
            byte[] bts2 = md5.ComputeHash(bts1);
            foreach (byte item in bts2)
            {
                result.Append(item.ToString("x2"));
            }
            return result.ToString();
        }