封装了MD5,SHA1等加密算法的类
来源:互联网 发布:数据挖掘异常检测算法 编辑:程序博客网 时间:2024/05/19 01:30
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;
}
}
}
- 一个封装了MD5,SHA1等加密算法的类
- ★ 封装了MD5,SHA1等加密算法的类
- 封装了MD5,SHA1等加密算法的类
- iOS的MD5/SHA1加密算法的实现
- iOS的MD5/SHA1加密算法的实现
- SHA1与MD5 加密算法
- MD5 SHA1 BASE64加密算法
- MD5 SHA1 BASE64加密算法
- 加密算法 AES MD5 SHA1
- c# 实现MD5,SHA1,SHA256,SHA512等常用加密算法
- c# 实现MD5,SHA1,SHA256,SHA512等常用加密算法
- 加密算法比较3DES AES RSA ECC MD5 SHA1等
- c# 实现MD5,SHA1,SHA256,SHA512等常用加密算法
- 加密算法比较3DES AES RSA ECC MD5 SHA1等
- 加密算法比较3DES AES RSA ECC MD5 SHA1等
- 加密算法比较3DES AES RSA ECC MD5 SHA1等
- 加密算法比较3DES AES RSA ECC MD5 SHA1等
- 加密算法比较3DES AES RSA ECC MD5 SHA1等
- SOA是灵丹妙药么
- 被涮了
- PHP IDE
- MS .NET平台下的Excel编程
- JAVA J2ME java ee众多源代码
- 封装了MD5,SHA1等加密算法的类
- Address Space 地址空间
- 长风SOA联盟发展模式探寻
- 域清单模式:企业成功实施SOA的最佳手段
- Axure RP Pro - jQuery - How to implement the "set focus" action
- 排序算法
- 从激情到平淡到失望,从无知无畏到畏首畏尾,不知什么时候我才能成熟面对人生百态
- 记忆中的程序设计题目
- AutoCAD中计算线加总长度