简单md5加密

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Security.Cryptography;
 5 using System.Text;
 6 using System.Threading.Tasks;
 7 
 8 namespace ConsoleApplication1
 9 {
10     class Program
11     {
12         static void Main(string[] args)
13         {
14             string s = getMD5("123");
15             Console.WriteLine("{0}",s);
16             Console.ReadKey();
17         }
18         public static string getMD5(string str)
19         {
20             MD5 md = MD5.Create();
21            //将字符转换成字节数组
22             byte[] buffer=Encoding.Default.GetBytes(str);
23             //返回加密好的字节数组
24             byte[] mdbuffer=md.ComputeHash(buffer);
25             //转换字节数组为字符串
26             //1、将字节数组的每个元素按照指定编码格式解析成字符串
27             //Encoding.GetEncoding("utf-8").GetString(mdbuffer);
28             //2.将每个元素都Tostring
29             string Tostr = "";
30             for (int i = 0; i < mdbuffer.Length; i++)
31             {
32                 //将十进制转换成16进制
33                 Tostr += mdbuffer[i].ToString("x");
34             }
35             return Tostr;
36         }     
37 
38     }
39 }

 

转载于:https://www.cnblogs.com/wangjiaxiaoxi/p/6265180.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值