使用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();
        }

猜你喜欢

转载自www.cnblogs.com/feiyucha/p/10976436.html