.NET下的加密解密大全(1): 哈希加密
.NET有丰富的加密解密API库供我们使用,本博文总结了.NET下的Hash散列算法,并制作成简单的DEMO,希望能对大家有所帮助。
MD5
[csharp]
using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Cryptography;
namespace EncryptAndDecrypt
{
public class MD5
{
public byte[] Hash(byte[] data)
{
System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
return md5.ComputeHash(data);
}
}
}
SHA1
[csharp]
using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Cryptography;
namespace EncryptAndDecrypt
{
public class SHA1:IHash
{
public byte[] Hash(byte[] data)
{
System.Security.Cryptography.SHA1 sha1 = System.Security.Cryptography.SHA1.Create();
return sha1.ComputeHash(data);
}
}
}
SHA256
[csharp]
using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Cryptography;
namespace EncryptAndDecrypt
{
public class SHA256:IHash
{
public byte[] Hash(byte[] data)
{
System.Security.Cryptography.SHA256 sha256= System.Security.Cryptography.SHA256.Create();
return sha256.ComputeHash(data);
}
}
}
SHA384
[csharp]
using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Cryptography;
namespace EncryptAndDecrypt
{
public class SHA384:IHash
{
public byte[] Hash(byte[] data)
{
System.Security.Cryptography.SHA384 sha384 = System.Security.Cryptography.SHA384.Create();
return sha384.ComputeHash(data);
}
}
}
SHA512
[csharp]
using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Cryptography;
namespace EncryptAndDecrypt
{
public class SHA512:IHash
{
public byte[] Hash(byte[] data)
{
System.Security.Cryptography.SHA512 sha512 = System.Security.Cryptography.SHA512.Create();
return sha512.ComputeHash(data);
}
}
}
.NET下的加密解密大全(1): 哈希加密的更多相关文章
- .NET下的加密解密大全(3):非对称加密
本博文列出了.NET下常用的非对称加密算法,并将它们制作成小DEMO,希望能对大家有所帮助. RSA[csharp]static string EnRSA(string data,string pub ...
- .NET下的加密解密大全(2):对称加密
本博文列出了.NET下常用的对称加密算法,并将它们制作成小DEMO,希望能对大家有所帮助. 公共代码[csharp]static byte[] CreateKey(int num) { byt ...
- python下RSA加密解密以及跨平台问题
Reference: http://www.cnblogs.com/luchanghong/archive/2012/07/18/2596886.html 项目合作需要,和其他网站通信,消息内容采用 ...
- Java加密解密大全
ChinaSEI系列讲义(By 郭克华) Java加密解密方法大全 如果有文字等小错,请多包涵.在不盈利的情况下,欢迎免费传播. 版权所有.郭克华 本讲义经 ...
- Linux下OpenSSL加密解密压缩文件(AES加密压缩文件)
OpenSSL是一个开源的用以实现SSL协议的产品,它主要包括了三个部分:密码算法库.应用程序.SSL协议库.Openssl实现了SSL协议所需要的大多数算法.下面介绍使用Openssl进行文件的对称 ...
- CentOS下Vim加密解密文本
CentOS用vim/vi给文件加密和解密 一. 利用 vim/vi 加密: 优点:加密后,如果不知道密码,就看不到明文,包括root用户也看不了: 缺点:很明显让别人知道加密了,容易让别人把加密的文 ...
- Python下RSA加密/解密, 签名/验证
原文是py2环境,而我的环境是py3,所以对原代码做了修改:decode(), encode() import rsa # 生成密钥 (pubkey, privkey) = rsa.newkeys(1 ...
- C#加密解密大全
1.方法一 (不可逆加密) public string EncryptPassword(string PasswordString,string PasswordFormat ) { ...
- python下RSA 加密/解密,签名/验证
基于win7 + python3.4 原文是py2环境,而我的环境是py3,所以对原代码做了修改:decode(), encode() import rsa # 生成密钥 (pubkey, privk ...
随机推荐
- Windows Azure案例分析: 选择虚拟机或云服务?
作者 王枫 发布于2013年6月27日 随着云计算技术和市场的日渐成熟,企业在考虑IT管理和运维时的选择也更加多样化,应用也从传统部署方式,发展为私有云.公有云.和混合云等部署方式.作为微软核心的公有 ...
- Android 在webView中创建web应用(译文)
如果你想在客户端添加一个web应用程序或者仅仅一个web页面,你可以通过使用WebView,WebView是基于android中View的扩展,能够在Activity的layout中实现显示网页,它不 ...
- (转载)查看三种MySQL字符集的方法
(转载)http://database.51cto.com/art/201010/229171.htm MySQL字符集多种多样,下面为您列举了其中三种最常见的MySQL字符集查看方法,该方法供您参考 ...
- POJ -- 1151
Atlantis Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 16222 Accepted: 6172 Descrip ...
- Rank of Tetris HDU--1881
Rank of Tetris Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- [leetcode]二分查找总结
Search for a Range 1.最简单的想法,用最普通的二分查找,找到target,然后向左右扩张,大量的重复的target,就会出现O(n)效率. class Solution { pub ...
- javascript检测属性
javascript 对象可以看做属性的集合.我们可以通过三种方式来判断某个属性是否存在于某个对象中. 1.in操作符 var o={x:1} "x" in o //True :x ...
- Linux 文件权限总结
在 Linux 中最基本的任务之一就是设置文件权限.理解它们是如何实现的是你进入 Linux 世界的第一步.如您所料,这一基本操作在类 UNIX 操作系统中大同小异.实际上,Linux 文件权限系统就 ...
- https_request请求接口返回数据
定义一个https_request方法 <?php function https_request($url, $data = null) { $curl = curl_init(); curl_ ...
- (int),Convert.ToInt32(),Int32.Parse(),Int32.TryParsed()的用法总结
1 (int) 强制转型为整型. 当将long,float,double,decimal等类型转换成int类型时可采用这种方式. double dblNum = 20; int intDblNum = ...