.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. SharePoint 2010 母版页制作的简单介绍

    转:http://www.cnblogs.com/jianyus/archive/2012/01/11/2319621.html 1.  首先打开SharePoint Designer 2010,找到 ...

  2. android左右晃动动画(红包左右晃动)

    TranslateAnimation animation = new TranslateAnimation(0, -5, 0, 0); animation.setInterpolator(new Ov ...

  3. HDU-1019 Least Common Multiple

    http://acm.hdu.edu.cn/showproblem.php?pid=1019 Least Common Multiple Time Limit: 2000/1000 MS (Java/ ...

  4. Ubuntu下安装mysql-python包

      sudo apt-get install libmysqld-dev sudo apt-get install libmysqlclient-dev sudo apt-get install py ...

  5. [SDOI2015]权值

    问题描述: 有一个长度为n的实数序列,,下标从1开始,其中第k个位置的实数为p · (sin(a · k + b) + cos(c · k + d) + 2),sin和cos采用弧度制,其中p,a,b ...

  6. 探讨Web组件化的实现

    CMS组件化,简单架构示意图: Web组件使用WebPage+WebAPI的好处: Ø  组件复用(组件条件管理页面复用+获取组件数据API复用). Ø  组件是分布式的第三方应用,本身高内聚.组件之 ...

  7. CSS选择器详解(伪类) 转 http://blog.csdn.net/Panda_m/article/details/50084699

    CSS选择器详解 之 伪类 伪类对大小写不敏感 结构伪类选择器 结构伪类是CSS3新增的类型选择器,利用DOM树实现元素过滤,通过文档结构的相互关系来匹配元素,可以减少class和id属性的定义,使文 ...

  8. crontab command not found

    在服务器上运行 crontab -e编辑定时任务 结果提示 command not found命令找不到,这就说明没安装crontab 由于 完整操作如下: [root@iZ11pvsxisqZ /] ...

  9. linux_tomcat7服务器日志爆满导致java崩溃的问题

    在linux服务器上部署Tomcat后,运行久了,catalina.out文件会越来越大,对系统的稳定造成了一定的影响. 最近刚刚出现了某台linux服务器上的java应用都假死或挂掉 然后我在输入命 ...

  10. SDK更新太慢

    同时,更新ADT和SDK Manager 在SDK Manager下Tools->Options打开了SDK Manager的Settings,选中“Force https://… source ...