.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. ssh 登录出现的几种错误以及解决办法

    首先.确保server端的ssh服务是开的(service shhd start) 然后在client端输入: ssh usrname@serverip (远程登录) scp filename usr ...

  2. Tag file directory /struts-tags does not start with "/WEB-INF/tags"

    使用自定义标签,记得引用路径 <%@taglib prefix="s" uri="/struts-tags" %>

  3. 逐行返回http响应的内容

    前言 问题:1.什么是特殊字符? 2.为什么要处理特殊字符? 答:特殊字符指相对于传统或常用的符号外,使用频率较少字符且难以直接输入的符号,比如数学符号:单位符号:制表符等 有些符号在URL中是不能直 ...

  4. Chrome 控制台实用指南【转】

    转自伯乐在线. Chrome 控制台实用指南 前言 Chrome浏览器我想是每一个前端er必用工具之一吧,一部分原因是它速度快,体积不大,支持的新特性也比其它浏览器多,还有一部分我想就是因为它的控制台 ...

  5. [App]Taste VS2015 && Android Studio

    逆水飞 尝试进行各种Android开发工具的安装以及大致流程对比 几个疑惑的地方 1)根据SDK的描述,应该是一个新版本的推出就有对应的包里面包含多个文件那么对于:SDK Platform.APIs. ...

  6. HDOJ/HDU 2203 亲和串(简单的判断~Java的indexOf()方法秒)

    Problem Description 人随着岁数的增长是越大越聪明还是越大越笨,这是一个值得全世界科学家思考的问题,同样的问题Eddy也一直在思考,因为他在很小的时候就知道亲和串如何判断了,但是发现 ...

  7. uva 10047 the monocyle (四维bfs)

    算法指南白书 维护一个四维数组,走一步更新一步 #include<cstdio> #include<cstring> #include<queue> #includ ...

  8. Bzoj 1616: [Usaco2008 Mar]Cow Travelling游荡的奶牛 动态规划

    1616: [Usaco2008 Mar]Cow Travelling游荡的奶牛 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1006  Solved: ...

  9. ASP.NET中设置一个定时器来定时更新 转

    asp.net 定时器 比较少用,  中国红木网这是一个相当实用的功能,有了RSS博客镜像,就不需要在多处同时发布博客日志了.比如你同时在新浪上有自己的博客,又同时有自己的个人博客站点,那么你只需要在 ...

  10. [转]Angular, Backbone, or Ember: Which is Best for your Build?

    In order to choose which framework is right for your build, we've asked four important questions of ...