源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

C#实现的MD5加密功能与用法示例

  • 时间:2020-01-18 08:44 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:C#实现的MD5加密功能与用法示例
本文实例讲述了C#实现的MD5加密功能与用法。分享给大家供大家参考,具体如下: 1、创建MD5Str.cs加密处理类
public class MD5Str
{
  /// <summary>
  /// 字符串MD5加密
  /// </summary>
  /// <param name="Text">要加密的字符串</param>
  /// <returns>密文</returns>
  public static string MD5(string Text)
  {
    byte[] buffer = System.Text.Encoding.Default.GetBytes(Text);
    try
    {
      System.Security.Cryptography.MD5CryptoServiceProvider check;
      check = new System.Security.Cryptography.MD5CryptoServiceProvider();
      byte[] somme = check.ComputeHash(buffer);
      string ret = "";
      foreach (byte a in somme)
      {
        if (a < 16)
          ret += "0" + a.ToString("X");
        else
          ret += a.ToString("X");
      }
      return ret.ToLower();
    }
    catch
    {
      throw;
    }
  }
}

2、运行测试
static void Main(string[] args)
{
  string data = "123456789"; //要加密的数据
  string encodeStr = "";  //加密后文本
  encodeStr = MD5Str.MD5(data);
  Console.WriteLine("原文本:{0}", data);
  Console.WriteLine("加密后文本:{0}", encodeStr);
  Console.Read();
}

[b]PS:关于加密解密感兴趣的朋友还可以参考本站在线工具:[/b] [b]MD5在线加密工具: [/b][url=http://tools.jb51.net/password/CreateMD5Password]http://tools.jb51.net/password/CreateMD5Password[/url] [b]迅雷、快车、旋风URL加密/解密工具: [/b][url=http://tools.jb51.net/password/urlrethunder]http://tools.jb51.net/password/urlrethunder[/url] [b]在线散列/哈希算法加密工具: [/b][url=http://tools.jb51.net/password/hash_encrypt]http://tools.jb51.net/password/hash_encrypt[/url] [b]在线MD5/hash/SHA-1/SHA-2/SHA-256/SHA-512/SHA-3/RIPEMD-160加密工具: [/b][url=http://tools.jb51.net/password/hash_md5_sha]http://tools.jb51.net/password/hash_md5_sha[/url] [b]在线sha1/sha224/sha256/sha384/sha512加密工具: [/b][url=http://tools.jb51.net/password/sha_encode]http://tools.jb51.net/password/sha_encode[/url] 更多关于C#相关内容还可查看本站专题:《[url=http://www.1sucai.cn/Special/173.htm]C#加密与解密算法与技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/611.htm]C#窗体操作技巧汇总[/url]》、《[url=http://www.1sucai.cn/Special/165.htm]C#常见控件用法教程[/url]》、《[url=http://www.1sucai.cn/Special/125.htm]WinForm控件用法总结[/url]》、《[url=http://www.1sucai.cn/Special/227.htm]C#程序设计之线程使用技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/805.htm]C#操作Excel技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/266.htm]C#中XML文件操作技巧汇总[/url]》、《[url=http://www.1sucai.cn/Special/116.htm]C#数据结构与算法教程[/url]》、《[url=http://www.1sucai.cn/Special/265.htm]C#数组操作技巧总结[/url]》及《[url=http://www.1sucai.cn/Special/478.htm]C#面向对象程序设计入门教程[/url]》 希望本文所述对大家C#程序设计有所帮助。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部