zoukankan      html  css  js  c++  java
  • 简单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 }
  • 相关阅读:
    Mybatis学习笔记
    Java——设计模式
    Java——多线程
    Java——集合
    DAO层、Service层、Controller层、View层
    Mybatis整合spring
    Spring中的DI和IOC
    事务
    Xml实现AOP
    2018.3.10考试的试题解析
  • 原文地址:https://www.cnblogs.com/wangjiaxiaoxi/p/6265180.html
Copyright © 2011-2022 走看看