首页 > 其他 > 详细

Md5加密

时间:2016-01-26 09:09:37      阅读:255      评论:0      收藏:0      [点我收藏+]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;

namespace _19_MD5加密
{
    class Program
    {
        static void Main(string[] args)
        {
             string exit = "";
           do{
              Console.WriteLine("请输入要加密的字符!");
              string str = Console.ReadLine();
              
              if (str != "q")
              {
                  //调用方法GetMd5(str)对输入的字符串进行加密
                  Console.WriteLine(GetMd5(str));
              }
              else {
                  break;
              }
            
              

           }while(exit!="q");//在!=Q的时候,继续循环

           Console.ReadKey();
        }
        public static  string GetMd5(string str) {
            //将字符串转成字符数组
            byte[] butffer = Encoding.Default.GetBytes(str);   
            MD5 md5pwd = MD5.Create();
            //将加密码后的数据保存到一个字符数组中
            byte [] output =md5pwd.ComputeHash(butffer);
            //定义一空字符串来接收数组里面数据
            string bytestr = "";
            //循环遍历数组,赋值给字符串
            for (int i = 0; i <output.Length; i++)
            {
                //加ToString是因为字符数组里面存储的是十进制,需要转换为16进制,
                //ToString("x2")表示转换为完整的16进制
                bytestr += output[i].ToString("x2");

            }

            //返回字符串
            return bytestr;
        
        }
    }
}

 

Md5加密

原文:http://www.cnblogs.com/hobe6699/p/5159270.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!