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

    MD5加密字符串

    
    
    引入命名空间
    using System.Security.Cryptography;

    方式一:
    public string GetMD5String(string pwd) { MD5CryptoServiceProvider md5=new MD5CryptoServiceProvide(); byte[] data=System.Text.Encoding.ASCII.GetBytes(pwd); byte[] md5data=md5.ComputeHash(data); StringBuilder builder=new StringBUilder(); for(int i=0;i<md5data.Length-1;i++) { builder.Append(md5data[i].ToString("X2")); } return builder; } 方式二: public string GetMd5(string msg) { string cryptStr = ""; MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider(); byte[] bytes = Encoding.UTF8.GetBytes(msg); byte[] cryptBytes = md5.ComputeHash(bytes); for (int i = 0; i < cryptBytes.Length; i++) { cryptStr += cryptBytes[i].ToString("X2"); } return cryptStr; }

    MD5加密文件

    
    
    引入命名空间
    using System.Security.Cryptography;

    string
    GetFileMd5(string path) { string ctyptStr = ""; byte[] cryptBytes; using (FileStream fs = new FileStream(path,FileMode.Open)) { MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider(); cryptBytes = md5.ComputeHash(fs); } for (int i = 0; i < cryptBytes.Length; i++) { ctyptStr += cryptBytes[i].ToString("X2"); } return ctyptStr; }
    更多详情请关注 http://www.cnblogs.com/baixingqiang/
  • 相关阅读:
    开始写游戏 --- 第三十一篇
    开始写游戏 --- 第三十篇
    开始写游戏 --- 第二十九篇
    开始写游戏 --- 第二十八篇
    高并发性能调试经验分享
    eclipse调试jdk源码
    synzhronized原理3
    内存屏障
    《JAVA NIO》读书笔记
    并发工具类
  • 原文地址:https://www.cnblogs.com/baixingqiang/p/5492232.html
Copyright © 2011-2022 走看看