C# MD5加密与校验 引用
using System;
using System.Security.Cryptography;
using System.Text; class Example
{
// Hash an input string and return the hash as
// a 32 character hexadecimal string.
static string getMd5Hash(string input)
{
// Create a new instance of the MD5CryptoServiceProvider object.
MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider(); // Convert the input string to a byte array and compute the hash.
byte[] data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(input)); // Create a new Stringbuilder to collect the bytes
// and create a string.
StringBuilder sBuilder = new StringBuilder(); // 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.
return sBuilder.ToString();
} // Verify a hash against a string.
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;
}
} static void Main()
{
string source = "Hello World!"; string hash = getMd5Hash(source); Console.WriteLine("The MD5 hash of " + source + " is: " + hash + "."); Console.WriteLine("Verifying the hash..."); if (verifyMd5Hash(source, hash))
{
Console.WriteLine("The hashes are the same.");
}
else
{
Console.WriteLine("The hashes are not same.");
} }
}
// This code example produces the following output:
//
// The MD5 hash of Hello World! is: ed076287532e86365e841e92bfc50d8c.
// Verifying the hash...
// The hashes are the same.
C# MD5加密与校验 引用的更多相关文章
- MD5工具类,提供字符串MD5加密、文件MD5值获取(校验)功能
MD5工具类,提供字符串MD5加密(校验).文件MD5值获取(校验)功能 : package com.yzu.utils; import java.io.File; import java.io.Fi ...
- Delphi MD5加密
Delphi MD5加密 1. 引用两个单元 uses IdHash,IdHashMessageDigest; 2.编写加密函数 function TEncrypti ...
- 前端请求参数MD5加密校验,参数串解密
首先引入MD5加密库:=>https://cdn.bootcss.com/blueimp-md5/2.10.0/js/md5.min.js; 步骤:=>1.请求前对参数进行字典升序排序,排 ...
- JAVAEE——SSH项目实战05:用户注册、登陆校验拦截器、员工拜访客户功能和MD5加密
作者: kent鹏 转载请注明出处: http://www.cnblogs.com/xieyupeng/p/7170519.html 一.用户注册 显示错误信息到页面上的另一种方法: public ...
- 【jar】JDK将单个的java文件打包为jar包,并引用到项目中使用【MD5加密】
==================================================================================================== ...
- MD5加密的引用
使用MD5 加密时 需要在后台代码中添加using System.Security.Cryptography; 引用 //MD5加密密码 byte[] a = MD5.Create().Compute ...
- 关于CryptoJS中md5加密以及aes加密的随笔
最近项目中用到了各种加密,其中就包括从没有接触过得aes加密,因此从网上各种查,官方的一种说法: 高级加密标准(英语:Advanced Encryption Standard,缩写:AES),在密码学 ...
- JS中使用MD5加密
下载 MD5 使用MD5加密的方法:下载md5.js文件,在网页中引用该文件: < script type="text/javascript" src="md5.j ...
- iOS,一行代码进行RSA、DES 、AES、MD5加密、解密
本文为投稿文章,作者:Flying_Einstein(简书) 加密的Demo,欢迎下载 JAVA端的加密解密,读者可以看我同事的这篇文章:http://www.jianshu.com/p/98569e ...
随机推荐
- MySQL错误Another MySQL daemon already running with the same unix socket.v
etc/init.d/mysqld start 结果显示 Another MySQL daemon already running with the same unix socket.显示另一个MyS ...
- 序列化和反序列化Java 8的时间/日期类
序列化 假如有 Clock 类: public class Clock { private LocalDate localDate; private LocalTime localTime; priv ...
- Mvp快速搭建商城购物车模块
代码地址如下:http://www.demodashi.com/demo/12834.html 前言: 说到MVP的时候其实大家都不陌生,但是涉及到实际项目中使用,还是有些无从下手.因此这里小编带着大 ...
- Phaser实现源代码剖析
Phaser是一个能够反复利用的同步栅栏.功能上与CyclicBarrier和CountDownLatch相似,只是提供更加灵活的使用方法.也就是说,Phaser的同步模型与它们几乎相同. 一般运用的 ...
- Silverlight实例教程 - Validation用户提交数据验证捕获(转载)
Silverlight 4 Validation验证实例系列 Silverlight实例教程 - Validation数据验证开篇 Silverlight实例教程 - Validation数据验证基础 ...
- centos httpd服务做yum本地源,以及安装Mysql
step0 首先centos的iso文件是有两张的,dvd1和dvd2,dvd2是额外的软件,常有的一些软件都在dvd1里面,而且repodata配置文件也在dvd1里面,如果直接把dvd2当做镜像文 ...
- RTT常用数据类型
RTT常用数据类型定义在rtdef.h中 /* RT-Thread basic data type definitions */ typedef signed char rt_int8_t; /**& ...
- VLC Web插件的浏览器兼容性
网页插件实现原理 IE浏览器基于Activex插件来实现,非IE浏览器采用NPAPI来实现,所以,非浏览器需要支持NPAPI来实现. IE浏览器 FF浏览器(版本小于52) 原因从 Firefox 版 ...
- 【转】Android自动化测试(UiAutomator)——UiObject
本文主要讲解使用UiAutomator的一些技巧,希望对于初学者有一定的帮助 UiObject 1.首先要声明对象 UiObject XXX = new UiObject(new Selector) ...
- ios --也是在B页面的生命周期设置如下代码。方法一是直接关闭和激活侧滑手势,方法二则是B遵循协议UIGestureRecognizerDelegate,设置侧滑交互代理,重写手势方法。
@property (weak, nonatomic) id<UIGestureRecognizerDelegate> restoreInteractivePopGestureDelega ...