using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Web;
using NLog; namespace services.Resources
{
public class MD5Util
{
private static Logger logger = LogManager.GetCurrentClassLogger(); public static string GetMd5Hash(string input)
{
// Create a new Stringbuilder to collect the bytes
// and create a string.
StringBuilder sBuilder = new StringBuilder(); using (MD5 md5Hash = MD5.Create())
{
// Convert the input string to a byte array and compute the hash.
byte[] data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(input)); // Loop through each byte of the hashed data
// and format each one as a hexadecimal string.
for (int i = ; i < data.Length; i++)
{
sBuilder.Append(data[i].ToString("x2"));
}
} // Return the hexadecimal string.
logger.Debug(sBuilder.ToString());
return sBuilder.ToString();
} // Verify a hash against a string.
public static bool VerifyMd5Hash(string input, string hash)
{
// Hash the input.
string hashOfInput = GetMd5Hash(input); // Create a StringComparer an compare the hashes.
StringComparer comparer = StringComparer.OrdinalIgnoreCase; if ( == comparer.Compare(hashOfInput, hash))
{
return true;
}
else
{
return false;
}
} }
}

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. Windows Kernel Security Training Courses

    http://www.codemachine.com/courses.html#kerdbg Windows Kernel Internals for Security Researchers Thi ...

  2. Is it possible to configure PostgreSQL to automatically close idle connections?

    1.use pgbouncer As new connections/transactions/statements arrive, the pool will increase in size up ...

  3. spring 初始化时注入bean实现listener的方法

    两种方法: 1.实现ApplicationListener<ContextRefreshedEvent>的onApplicationEvent(ContextRefreshedEvent ...

  4. C# 中DataTable转成模型List

    C# 中DataTable转成模型List 引入using System.Reflection; 命名空间 使用注意实体类的属性名必须和DataTable的列名一致 使用: DBList<Sto ...

  5. 一个PHP数组能占多大内存

    最近用PHP读取一个大文件把相关数据存放到数组中,之后处理并输出, 读取过程中发现占用内存很大, 于是很好奇这个问题. 简单的写一个代码 <?php $m1 = memory_get_usage ...

  6. 15条变量&方法命名的最佳实践【转】

    原文地址:15 Best Practices of Variable & Method Naming 不同的代码段采用不同的命名长度.通常来说,循环计数器(loop counters)采用1位 ...

  7. Maven最佳实践:版本管理

    什么是版本管理 首先,这里说的版本管理(version management)不是指版本控制(version control),但是本文假设你拥有基本的版本控制的知识,了解subversion的基本用 ...

  8. Js数组去重复取唯一值

    function isBigEnough(element) { return element >= 10; } var filtered = [12, 5, 8, 130, 44].filter ...

  9. [算法] 数据结构之AVL树

    1 .基本概念 AVL树的复杂程度真是比二叉搜索树高了整整一个数量级——它的原理并不难弄懂,但要把它用代码实现出来还真的有点费脑筋.下面我们来看看: 1.1  AVL树是什么? AVL树本质上还是一棵 ...

  10. [mysql] mysql explain 使用

    explain显示了mysql如何使用索引来处理select语句以及连接表.可以帮助选择更好的索引和写出更优化的查询语句. 先解析一条sql语句,看出现什么内容 EXPLAINSELECTs.uid, ...