★ 封装了MD5,SHA1等加密算法的类

使用Aosu易博通,一分钱不花,实现网文自动摘抄, 博客写作方便又快捷,和您现在看到的一样 !自主嵌入Google广告,还能赚取美金! 现在就下载

src="http://aosustudio.com.cn//Upload/Articles/070325/fd048511-18fd-4b65-a776-a48ec09fc11d/3860cd0b-402e-4bd0-8593-64fb0d37a21b.html" frameborder="0" width="100%" scrolling="no" height="270">

 
using  System;
using  System.Collections.Generic;
using  System.Text;
using  System.Security.Cryptography;

namespace  trips
{
    
static class CryptClass
    
{
        
public enum HashType : int
        
{
            SHA1,
            SHA256,
            SHA384,
            SHA512,
            MD5,
            RIPEMD160
        }



        
public static string FromString(string input, HashType hashtype)
        
{
            Byte[] clearBytes;
            Byte[] hashedBytes;
            
string output = String.Empty;

            
switch (hashtype)
            
{
                
case HashType.RIPEMD160:
                    clearBytes 
= new UTF8Encoding().GetBytes(input);
                    RIPEMD160 myRIPEMD160 
= RIPEMD160Managed.Create();
                    hashedBytes 
= myRIPEMD160.ComputeHash(clearBytes);
                    output 
= BitConverter.ToString(hashedBytes).Replace("-""").ToLower();
                    
break;
                
case HashType.MD5:
                    clearBytes 
= new UTF8Encoding().GetBytes(input);
                    hashedBytes 
= ((HashAlgorithm)CryptoConfig.CreateFromName("MD5")).ComputeHash(clearBytes);
                    output 
= BitConverter.ToString(hashedBytes).Replace("-""").ToLower();
                    
break;
                
case HashType.SHA1:
                    clearBytes 
= Encoding.UTF8.GetBytes(input);
                    SHA1CryptoServiceProvider sha1 
= new SHA1CryptoServiceProvider();
                    sha1.ComputeHash(clearBytes);
                    hashedBytes 
= sha1.Hash;
                    sha1.Clear();
                    output 
= BitConverter.ToString(hashedBytes).Replace("-""").ToLower();
                    
break;
                
case HashType.SHA256:
                    clearBytes 
= Encoding.UTF8.GetBytes(input);
                    SHA256 sha256 
= new SHA256Managed();
                    sha256.ComputeHash(clearBytes);
                    hashedBytes 
= sha256.Hash;
                    sha256.Clear();
                    output 
= BitConverter.ToString(hashedBytes).Replace("-""").ToLower();
                    
break;
                
case HashType.SHA384:
                    clearBytes 
= Encoding.UTF8.GetBytes(input);
                    SHA384 sha384 
= new SHA384Managed();
                    sha384.ComputeHash(clearBytes);
                    hashedBytes 
= sha384.Hash;
                    sha384.Clear();
                    output 
= BitConverter.ToString(hashedBytes).Replace("-""").ToLower();
                    
break;
                
case HashType.SHA512:
                    clearBytes 
= Encoding.UTF8.GetBytes(input);
                    SHA512 sha512 
= new SHA512Managed();
                    sha512.ComputeHash(clearBytes);
                    hashedBytes 
= sha512.Hash;
                    sha512.Clear();
                    output 
= BitConverter.ToString(hashedBytes).Replace("-""").ToLower();
                    
break;
            }

            
return output;
        }


    }

}
 


 
今日热点:

src="http://aosustudio.com.cn/ad/GoogleSerch.htm" frameborder="0" width="100%" scrolling="no" height="30">

 
 
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值