zoukankan      html  css  js  c++  java
  • MD5加密

     1 using System;
     2 using System.Collections.Generic;
     3 using System.IO;
     4 using System.Linq;
     5 using System.Security.Cryptography;
     6 using System.Text;
     7 using System.Threading.Tasks;
     8 
     9 namespace ConsoleApplication6
    10 {
    11     class Program
    12     {
    13         static void Main(string[] args)
    14         {
    15             //张三 123
    16             string str = "123";
    17             string md5 = GetMd5(str);
    18             Console.WriteLine(md5);
    19             Console.ReadKey();
    20         }
    21         static string GetMd5(string str)
    22         {
    23             MD5 md5 = MD5.Create();//创建MD5实例对象
    24             //开始加密
    25             //将传入对象转换为字节数字
    26             byte[] blist = Encoding.Default.GetBytes(str);
    27             //将字节数组传入加密方法里面,返回一个字节数组
    28             byte[] bmd5list = md5.ComputeHash(blist);
    29             //将字节数组转换为string
    30             StringBuilder sb = new StringBuilder();
    31             for (int i = 0; i < bmd5list.Length; i++)
    32             {
    33                 sb.Append(bmd5list[i].ToString("x2"));//x表示将十进制转换为16进制。2表示每次都是两位数
    34             }
    35             return sb.ToString();
    36         }
    37     }
    38 }

     md5加密不可逆。如果要进行比对,可以先进行加密,对比加密后的值是否想等。

  • 相关阅读:
    luogu P3174 毛毛虫
    P3386二分图最大匹配模版
    P4180 严格次小生成树
    差分约束
    高斯消元
    P1306 斐波那契公约数
    极值
    排序
    P1852 [国家集训队]跳跳棋
    高精度模版
  • 原文地址:https://www.cnblogs.com/wwz-wwz/p/6391111.html
Copyright © 2011-2022 走看看