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. C#字符补位

    C#字符补位 .byte类型的字符,用5位2进制数表示,右对齐,不足5位,前面补零. byte b; Convert.ToString(b, ).PadLeft(, ') .byte类型的字符,用2位 ...

  2. 转(JSONP处理跨域事件)

     前言: 由于Sencha Touch 2这种开发模式的特性,基本决定了它原生的数据交互行为几乎只能通过AJAX来实现. 当然了,通过调用强大的PhoneGap插件然后打包,你可以实现100%的Soc ...

  3. UserDefault的使用,保存小数据到本地-iOS

    //保持到本地数据 NSArray *array=@[@"234",@"sdfe"]; NSUserDefaults *userDefault=[NSUserD ...

  4. XML序列化中含有List的情况,序列化到根节点下一层

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.X ...

  5. mysql提权笔记

    最近小菜遇到mysql提权,总是会搞错,就记记笔记吧!以后方便用 先说手工吧! mysql<5.0,导出路径随意:5.0<=mysql<5.1,则需要导出至目标服务器的系统目录(如: ...

  6. 二十四种设计模式:状态模式(State Pattern)

    状态模式(State Pattern) 介绍允许一个对象在其内部状态改变时改变它的行为.对象看起来似乎修改了它所属的类. 示例有一个Message实体类,对它的操作有Insert()和Get()方法, ...

  7. how-to-install-hyper-v-on-a-virtual-machine-in-hyper-v.aspx

    BEFORE STARTING IT IS IMPORTANT TO KNOW THAT THIS ENVIRONMENT IS NOT SUPPORTED BY MICROSOFT. USE IT ...

  8. unity, Animation crossfade需要两动画在时间上确实有交叠

    unity现在播动画都用Animator了,但公司的老项用的还是Animation,今天遇到一个bug,是两个动画的衔接处不连贯. 最后发现是由于A动画已经播完之后B动画才开始播,而且还用了cross ...

  9. Javax.mail.NoSuchProviderException: smtp

    UT 这个错误是因为缺jar包 下载地址:在oralce下载一个 JavaMail 包 http://www.oracle.com/technetwork/java/javamail/index-13 ...

  10. Readonly和Disabled的区别

    readonly 把输入的字段设为只读,但是没有禁用 readonly=” readonly”; disabled 禁用一个input元素. disabled="disabled" ...