.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. The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.

    The server is temporarily unable to service your request due to maintenance downtime or capacity pro ...

  2. Net中的反射使用入门

    [转载] MSDN:ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/cpguide/html/cpcondiscoveringtypeinformatio ...

  3. [原]RobotFrameWork(十一)AutoItLibrary测试库在win7(64bit)下安装及简单使用

    最近安装AutoItLibrary,发现在win7 x64下无法安装成功,后来经过定位,发现是3rdPartyTools\AutoIt目录下面AutoItX3.dll的问题.因为AutoItX3.dl ...

  4. 提高IIS的并发量

    IIS 7.0使用的是默认配置,服务器最多只能处理5000个同时请求. 根据相关文档调整设置,可以让服务器从设置上支持10万个同时请求 . 调整IIS 7应用程序池队列长度 由原来的默认1000改为6 ...

  5. Linux Mono Asp.net 部署方案

    1.Jexus 国内的 官网:http://www.jexus.org 2.Apache 官网:http://mono-project.com/Mod_mono 3.Nginx 官网:http://m ...

  6. JavaScript高级程序设计60.pdf

    错误处理 try-catch语句 try{ //可能会导致错误的代码 }catch(error){ //在错误发生时如何处理 } error是一个包含着错误信息的对象,它有一个message属性,保存 ...

  7. WORD文档的长串数字如何粘贴到excel

    有问题,才有提高 问题描述: 现 word 文档中有好多长长的数字(如下),我需要将它们弄进 Excel 中 直接[复制],[粘贴],结果显示如下: 然后再设置单元格格式中的数字,无论选哪一个都得不到 ...

  8. 一个PHP书单 -摘自网络

    # PHP <PHP程序设计>(第2版) –PHP语法和入门最好的书 <PHP5权威编程> –PHP入门后升级书 <深入PHP:面向对象.模式与实践>(第3版) – ...

  9. 【JAVA - SSM】之MyBatis与原生JDBC、Hibernate访问数据库的比较

    首先来看一下原生JDBC访问数据库的代码: public static void main(String[] args) { // 数据库连接 Connection connection = null ...

  10. [D3] 2. Basics of SVG

    1. svg should use 'fill' prop instead 'background-color'2. svg width & height no need 'px'3. att ...