.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 ...
随机推荐
- UIImagePickerController 如何显示中文界面
1: 添加中文的 Localizations Project --> Info --> Localizations 添加 "Chinese(Simplified)" ...
- Web三维技术:Flash Builder+away3d平台搭建(含演示视频)
转自:http://www.cnblogs.com/beer/archive/2011/07/08/2101492.html 前言:作为页面中实验设备的显示层,需要一个swf作为显示的UI.虽然可以用 ...
- SQLServer使用规范(转载)
SQLServer使用规范 常见的字段类型选择 1.字符类型建议采用varchar/nvarchar数据类型 2.金额货币建议采用money数据类型 3.科学计数建议采用numeric数据类型 4.自 ...
- 2D游戏编程1--windows编程模型
一.创建一个windows程序步骤 1.创建一个windows类 2.创建一个事件处理程序 3.注册windows类 4.用之前创建的windows类创建一个窗口 5.创建一个主事件循环 二.存储 ...
- [LeetCode] 74. Search a 2D Matrix 解题思路
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the follo ...
- Git(一)环境搭建 + 常用命令
上周研究了一下 Git,简单的使用了一下,个人感觉相对 SVN 来说还是有一定学习成本的,这次记录一些自己的学习过程以及常用的命令. 在学习的过程中,同事推荐了一个前辈写的教程([传送门]:Git教程 ...
- 调试postgresql9.5.2最新源码
最近在考量数据库的选型,考虑后期把数据切换到postgresql ,postgresql源码用c实现,代码很精炼完美,值得学习下 首先去pgsql官网下载最新的源码 ,然后还需要perl,bison ...
- HTML5 汽泡效果
又到了晚上了,精神只有在晚上的时候才能爆发,可能程序员的命吧.废话就不多说了,今天我为大家带来的是一个气泡的效果. 代码下载 下面请看效果图
- Java多线程小结
简述 Java是支持多线程编程的语言,线程相比于进程更加轻量级,线程共享相同的内存空间,但是拥有独立的栈.减少了进程建立.销毁的资源消耗.jdk1.5后对java的多线程编程提供了更完善的支持,使得j ...
- SystemTimeToFileTime、FileTimeToLocalFileTime、LocalFileTimeToFileTime三函数的跨平台实现
// test.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <stdlib.h> #include & ...