posts - 134,  comments - 22,  trackbacks - 0
 1在开头加引用:
 2using System.Security.Cryptography;
 3
 4MD5加密:
 5            public static string MD5Encrypt(string password)
 6            {
 7                string text = password;
 8                MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider(); //实例化MD5加密类
 9                byte[] bytValue, bytHash;
10                bytValue = System.Text.Encoding.UTF8.GetBytes(text);//转换明文文本为Byte
11                bytHash = md5.ComputeHash(bytValue);//以散列的方式加密文本
12                md5.Clear();
13                string sTemp = "";
14                for (int i = 0; i < bytHash.Length; i++)
15                {
16                    sTemp += bytHash[i].ToString("X").PadLeft(2'0');//把加密后的密文转换成32位十六进制的字符串
17                }
18                return sTemp;//返回结果
19            }
20
posted on 2007-07-03 15:54 TRE-China R&D 阅读(396) 评论(0)  编辑 收藏 引用 所属分类: ASP.NETC#
只有注册用户登录后才能发表评论。