码迷,mamicode.com
首页 > Windows程序 > 详细

C#MD5 32位加密

时间:2015-12-29 12:49:45      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:

using System.Security.Cryptography;

public static string En32(string str)
        {
            string pwd = "";
            MD5 md5 = MD5.Create();//实例化一个md5对像
            // 加密后是一个字节类型的数组,这里要注意编码UTF8/Unicode等的选择 
            byte[] s = md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(str));
            // 通过使用循环,将字节类型的数组转换为字符串,此字符串是常规字符格式化所得
            for (int i = 0; i < s.Length; i++)
            {
                //将得到的字符串使用十六进制类型格式,格式后的字符是小写的字母,如果使用大写(X)则格式后的字符是大写字符 
                pwd = pwd + s[i].ToString("x2");
            }
            return pwd;
        }
 

 

C#MD5 32位加密

标签:

原文地址:http://www.cnblogs.com/zhaohaoran/p/5085233.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!