zoukankan      html  css  js  c++  java
  • .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); 
            } 
        } 

  • 相关阅读:
    snmp安装zabbix
    〖Demo〗-- 用Django实现Video页面分类查询
    〖Python〗-- Django的ORM性能优化建议
    〖Web〗-- 新特性之WebSocket
    〖Python〗-- 数据结构
    〖缓存〗-- Memcached 与 Redis
    〖算法〗-- NB二人组:堆排序、归并排序
    〖算法〗-- 快速排序 、希尔排序、计数排序
    〖算法〗-- 排序lowB三人组:冒泡排序、选择排序、 插入排序
    〖算法〗-- 递归、二分查找、列表查找
  • 原文地址:https://www.cnblogs.com/gjhjoy/p/3501662.html
Copyright © 2011-2022 走看看