MD5, SHA1, SHA256 and SHA512 Hash Algorithm Functions in C#
来源:互联网 发布:淘宝信誉值怎么提升 编辑:程序博客网 时间:2024/06/05 00:16
using System;using System.Security.Cryptography;using System.Text;namespace Hash{ public class Hash { public Hash() { } public enum HashType : int { MD5, SHA1, SHA256, SHA512 } public static string GetHash(string text, HashType hashType) { string hashString; switch (hashType) { case HashType.MD5: hashString = GetMD5(text); break; case HashType.SHA1: hashString = GetSHA1(text); break; case HashType.SHA256: hashString = GetSHA256(text); break; case HashType.SHA512: hashString = GetSHA512(text); break; default: hashString = "Invalid Hash Type"; break; } return hashString; } public static bool CheckHash(string original, string hashString, HashType hashType) { string originalHash = GetHash(original, hashType); return (originalHash == hashString); } private static string GetMD5(string text) { UnicodeEncoding UE = new UnicodeEncoding(); byte[] hashValue; byte[] message = UE.GetBytes(text); MD5 hashString = new MD5CryptoServiceProvider(); string hex = ""; hashValue = hashString.ComputeHash(message); foreach (byte x in hashValue) { hex += String.Format("{0:x2}", x); } return hex; } private static string GetSHA1(string text) { UnicodeEncoding UE = new UnicodeEncoding(); byte[] hashValue; byte[] message = UE.GetBytes(text); SHA1Managed hashString = new SHA1Managed(); string hex = ""; hashValue = hashString.ComputeHash(message); foreach (byte x in hashValue) { hex += String.Format("{0:x2}", x); } return hex; } private static string GetSHA256(string text) { UnicodeEncoding UE = new UnicodeEncoding(); byte[] hashValue; byte[] message = UE.GetBytes(text); SHA256Managed hashString = new SHA256Managed(); string hex = ""; hashValue = hashString.ComputeHash(message); foreach (byte x in hashValue) { hex += String.Format("{0:x2}", x); } return hex; } private static string GetSHA512(string text) { UnicodeEncoding UE = new UnicodeEncoding(); byte[] hashValue; byte[] message = UE.GetBytes(text); SHA512Managed hashString = new SHA512Managed(); string hex = ""; hashValue = hashString.ComputeHash(message); foreach (byte x in hashValue) { hex += String.Format("{0:x2}", x); } return hex; } }}
- MD5, SHA1, SHA256 and SHA512 Hash Algorithm Functions in C#
- Windows store app Hash(MD5/SHA1/SHA256/SHA384/SHA512)
- c# 实现MD5,SHA1,SHA256,SHA512等常用加密算法
- c# 实现MD5,SHA1,SHA256,SHA512等常用加密算法
- c# 实现MD5,SHA1,SHA256,SHA512等常用加密算法
- c# 实现MD5,SHA1,SHA256,SHA512等常用加密算法
- C语言实现MD5/SHA1/SHA256/SHA512
- 完整加密类(提供MD5,SHA1,SHA256,SHA512,DES加密和解密)
- [VB.Net]MD5/MD160/SHA1/SHA256/SHA384/SHA512/Base64-Encode/Base64-Decode
- 如何利用openssl来计算md4, md5, sha1, sha256, sha384, sha512等常用哈希值?
- 用OpenSSL 做HMAC(sha512/sha256/sha1/md5/sha224/sha384/sha/md2)
- .net实现md5加密 sha1加密 sha256加密 sha384加密 sha512加密 des加密解密
- 如何利用openssl来计算md4, md5, sha1, sha256, sha384, sha512等常用哈希值?
- MD5、SHA256、SHA512加密算法,以及可逆算法
- MD5, SHA256, SHA512哈希算法
- 获取MD5、SHA1、SHA256码
- studio获得sha1 md5 sha256
- 再次利用openssl来计算sha1, sha224, sha256, sha384, sha512
- 关于WINSOCK.H与winsock2.h中的重定义解决办法分析
- LDD3学习笔记(10):延时和延后
- Sql Server 查看锁表
- 解决问题“Error inflating class android.widget.RelativeLayout”
- sql语句的批量更新
- MD5, SHA1, SHA256 and SHA512 Hash Algorithm Functions in C#
- 光纤收发器接口类型、连接、指示灯说明及故障症断
- linux(Debian)通过代理上网
- STL之二分查找 (Binary search in STL)
- Builder------设计模式
- excel导出范例
- linux 下Time_wait过多问题解决
- 光通信学习资料之光纤收发器的安装
- windbg 启动参数,常用命令