C#MD5加密16进制写法

来源:互联网 发布:beta软件计划 编辑:程序博客网 时间:2024/05/20 20:56
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;

namespace Md5
{
    class Program
    {
        static void Main(string[] args)
        
        {
 //调用加密方法
     string a=           Getmd5("2122211212121212");
     Console.Write(a);
            Console.ReadKey();
        }
        //MD5加密方法写法
        public static string Getmd5(string str)
        {
            //创建MD5对像
            MD5 md5 = MD5.Create();
            //将字符串转换成数组
            byte[] ba = Encoding.Default.GetBytes(str);
            //将数组加密 成  加密数组
          byte[] md55= md5.ComputeHash(ba);
              //将加密数组编译成字符串
         // return Encoding.Default.GetString(md55);
            //
          string STR = "";
            //便利数组中元素转化成字符并拼接
          for (int I = 0; I < md55.Length; I++)
          {
              //X 表是10进制,X2表示16进制

              STR += md55[I].ToString("x2");
          
          }
          return STR;
        }
    }
}

0 0