1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Security.Cryptography;
  5. using System.Text;
  6. using System.Web;
  7. using NLog;
  8.  
  9. namespace services.Resources
  10. {
  11. public class MD5Util
  12. {
  13. private static Logger logger = LogManager.GetCurrentClassLogger();
  14.  
  15. public static string GetMd5Hash(string input)
  16. {
  17. // Create a new Stringbuilder to collect the bytes
  18. // and create a string.
  19. StringBuilder sBuilder = new StringBuilder();
  20.  
  21. using (MD5 md5Hash = MD5.Create())
  22. {
  23. // Convert the input string to a byte array and compute the hash.
  24. byte[] data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(input));
  25.  
  26. // Loop through each byte of the hashed data
  27. // and format each one as a hexadecimal string.
  28. for (int i = ; i < data.Length; i++)
  29. {
  30. sBuilder.Append(data[i].ToString("x2"));
  31. }
  32. }
  33.  
  34. // Return the hexadecimal string.
  35. logger.Debug(sBuilder.ToString());
  36. return sBuilder.ToString();
  37. }
  38.  
  39. // Verify a hash against a string.
  40. public static bool VerifyMd5Hash(string input, string hash)
  41. {
  42. // Hash the input.
  43. string hashOfInput = GetMd5Hash(input);
  44.  
  45. // Create a StringComparer an compare the hashes.
  46. StringComparer comparer = StringComparer.OrdinalIgnoreCase;
  47.  
  48. if ( == comparer.Compare(hashOfInput, hash))
  49. {
  50. return true;
  51. }
  52. else
  53. {
  54. return false;
  55. }
  56. }
  57.  
  58. }
  59. }

code md5的更多相关文章

  1. iOS开发 - 网络数据安全加密(MD5)

    提交用户的隐私数据 一定要使用POST请求提交用户的隐私数据GET请求的所有参数都直接暴露在URL中请求的URL一般会记录在服务器的访问日志中服务器的访问日志是黑客攻击的重点对象之一 用户的隐私数据登 ...

  2. JQuery - MD5加密

    效果: JS代码: 命名为任意名称,一般为:Jquery.md5.js /** * jQuery MD5 hash algorithm function * * <code> * Calc ...

  3. jQuery的md5加密插件及其它js md5加密代码

    /** * jQuery MD5 hash algorithm function * * <code> * Calculate the md5 hash of a String * Str ...

  4. jquery MD5

    /** * jQuery MD5 hash algorithm function * * <code> * Calculate the md5 hash of a String * Str ...

  5. 【javascript类库】zepto和jquery的md5加密插件

    [javascript类库]zepto和jquery的md5加密插件 相信很多人对jQuery并不陌生,这款封装良好的插件被很多开发者使用. zepto可以说是jQuery在移动端的替代产品,它比jQ ...

  6. JavaScript-Tool:jquery.md5.js

    ylbtech-JavaScript-Tool:jquery.md5.js 1.返回顶部 1. 引入js后 使用方法:document.write($.md5('1234')); 加密结果:81dc9 ...

  7. MD5加密处理

    无论传送过程和存储方式,都是以明文的方式,很不安全!一旦泄漏,将会造成很大的损失! 插件名称jQuery.MD5.js: /** * jQuery MD5 hash algorithm functio ...

  8. 前端加密MD5

    今天接触了MD5加密方式,记录一下使用方法,又去搜了搜关于MD5的详细内容 MD5在vue中使用方法 1.下载MD5模块 cnpm install md5 -S 2.引入模块 const md5 = ...

  9. 如何对数据进行MD5加密

    前端进行加密 /** * jQuery MD5 hash algorithm function * * <code> * Calculate the md5 hash of a Strin ...

随机推荐

  1. UIview 学习与自定义--ios

    UIView *view1=[[UIView alloc] initWithFrame:CGRectMake(50, 50, 100, 100)]; view1.backgroundColor=[UI ...

  2. C# Timer用法及实例详解

    C# Timer用法有哪些呢?我们在使用C# Timer时都会有自己的一些总结,那么这里向你介绍3种方法,希望对你了解和学习C# Timer使用的方法有所帮助. 关于C# Timer类  在C#里关于 ...

  3. SignalR的安装

    介绍 SignalR 是 ASP.NET 团队正在开发的一个 Microsoft .NET Framework 库和 jQuery 插件,可能包括在以后版本的 ASP.NET 平台中. 它提供了一些前 ...

  4. JavaScript对SVG进行操作的相关技术

    原文地址:http://www.ibm.com/developerworks/cn/xml/x-svgscript/   本文主要介绍在 SVG 中通过编程实现动态操作 SVG 图像的知识. SVG ...

  5. mysql 索引过长1071-max key length is 767 byte

    问题 create table: Specified key was too long; max key length is 767 bytes   原因 数据库表采用utf8编码,其中varchar ...

  6. Q5: Remove Duplicates from Sorted Array

    问题描述: Given a sorted array, remove the duplicates in place such that each element appear only once a ...

  7. 常用邮件 smtp pop

    常用的邮箱服务器(SMTP.POP3)地址.端口  sina.com: POP3服务器地址:pop3.sina.com.cn(端口:110) SMTP服务器地址:smtp.sina.com.cn(端口 ...

  8. 运用cookie登陆人人网爬取数据

    浏览器访问WEB服务器的过程 在用户访问网页时,不论是通过URL输入域名或IP,还是点击链接,浏览器向WEB服务器发出了一个HTTP请求(Http Request),WEB服务器接收到客户端浏览器的请 ...

  9. 取消GridView/ListView item被点击时的效果

    方法一,在控件被初始化的时候设置 ? 1 2 gridView.setSelector(new ColorDrawable(Color.TRANSPARENT)); listView.setSelec ...

  10. presto访问 Azure blob storage

    当集群使用Azure Blog Storage时,prestoDB无法获取返回结果,在此记录下 如下,hive里面的两个表,一个使用的是本地的hdfs,一个是使用 azure blob storage ...