.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): 哈希加密的更多相关文章

  1. .NET下的加密解密大全(3):非对称加密

    本博文列出了.NET下常用的非对称加密算法,并将它们制作成小DEMO,希望能对大家有所帮助. RSA[csharp]static string EnRSA(string data,string pub ...

  2. .NET下的加密解密大全(2):对称加密

    本博文列出了.NET下常用的对称加密算法,并将它们制作成小DEMO,希望能对大家有所帮助. 公共代码[csharp]static byte[] CreateKey(int num) {     byt ...

  3. python下RSA加密解密以及跨平台问题

    Reference:  http://www.cnblogs.com/luchanghong/archive/2012/07/18/2596886.html 项目合作需要,和其他网站通信,消息内容采用 ...

  4. Java加密解密大全

    ChinaSEI系列讲义(By 郭克华)   Java加密解密方法大全                     如果有文字等小错,请多包涵.在不盈利的情况下,欢迎免费传播. 版权所有.郭克华 本讲义经 ...

  5. Linux下OpenSSL加密解密压缩文件(AES加密压缩文件)

    OpenSSL是一个开源的用以实现SSL协议的产品,它主要包括了三个部分:密码算法库.应用程序.SSL协议库.Openssl实现了SSL协议所需要的大多数算法.下面介绍使用Openssl进行文件的对称 ...

  6. CentOS下Vim加密解密文本

    CentOS用vim/vi给文件加密和解密 一. 利用 vim/vi 加密: 优点:加密后,如果不知道密码,就看不到明文,包括root用户也看不了: 缺点:很明显让别人知道加密了,容易让别人把加密的文 ...

  7. Python下RSA加密/解密, 签名/验证

    原文是py2环境,而我的环境是py3,所以对原代码做了修改:decode(), encode() import rsa # 生成密钥 (pubkey, privkey) = rsa.newkeys(1 ...

  8. C#加密解密大全

    1.方法一 (不可逆加密)     public string EncryptPassword(string PasswordString,string PasswordFormat )      { ...

  9. python下RSA 加密/解密,签名/验证

    基于win7 + python3.4 原文是py2环境,而我的环境是py3,所以对原代码做了修改:decode(), encode() import rsa # 生成密钥 (pubkey, privk ...

随机推荐

  1. 从零开始学习jQuery

    转自:http://www.cnblogs.com/zhangziqiu/archive/2009/04/30/jQuery-Learn-1.html 本系列文章导航 从零开始学习jQuery (一) ...

  2. Windows环境下Android NDK环境搭建

    前面介绍Windows下Android 开发环境配置,主要是面向JAVA开发环境,对只做APK上层应用开发人员来讲,基本够用了,由于Linux系统的权限限制和Android封装架构限制,很多涉及底层设 ...

  3. win7下安装load generator

    win7下只安装loadrunner load generator 1.点击setup.exe 2.选择“loadrunner 完整安装程序”   3.安装完成所需要的插件,然后重启 4.重新打开安装 ...

  4. Bzoj 3343: 教主的魔法 分块,二分

    3343: 教主的魔法 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 821  Solved: 364[Submit][Status][Discuss ...

  5. [LeetCode] 287. Find the Duplicate Number 解题思路

    Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), pro ...

  6. usaco 猜数游戏

    Description 为了提高智商,锻炼思维能力,奶牛设计了一个猜数游戏.游戏开始前,贝西会在牛棚后面摆上N个数字.所有数字排成一条直线,按次序从1到N编号.每个数字在1到10^9之间,没有两个数字 ...

  7. lost connection to mysql server at "reading initial communication packet",system error:2

  8. hdoj 1896 Stones【优先队列】

    Stones Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Subm ...

  9. WordPress文件上传与下载问题解决

    网上流传了一些修改WordPress文件上传大小限制的做法,大部分是一个版本,而且说得不够准确,特别是对于生手的指导性不强,本文总结了使用Wordpress博客的朋友在文件上传与下载时大小限制,及文件 ...

  10. DIV+CSS布局-固定页面开度布局

    DIV+CSS布局中主要CSS属性介绍: Float: Float属性是DIV+CSS布局中最基本也是最常用的属性,用于实现多列功能,我们知道<div>标签默认一行只能显示一个,而使用Fl ...