HashEncode哈希加密算法幫助類庫
哈希加密一個(gè)字符串
得到隨機(jī)哈希加密字符串
using System;
using System.Text;
using System.Security.Cryptography;
namespace JsonsHashEncode
{
/// <summary>
/// 得到隨機(jī)安全碼(哈希加密)。
/// </summary>
public class HashEncode
{
public HashEncode()
{
//
// TODO: 在此處添加構(gòu)造函數(shù)邏輯
//
}
/// <summary>
/// 得到隨機(jī)哈希加密字符串
/// </summary>
/// <returns></returns>
public static string GetSecurity()
{
string Security = HashEncoding(GetRandomValue());
return Security;
}
/// <summary>
/// 得到一個(gè)隨機(jī)數(shù)值
/// </summary>
/// <returns></returns>
public static string GetRandomValue()
{
Random Seed = new Random();
string RandomVaule = Seed.Next(1, int.MaxValue).ToString();
return RandomVaule;
}
/// <summary>
/// 哈希加密一個(gè)字符串
/// </summary>
/// <param name="Security"></param>
/// <returns></returns>
public static string HashEncoding(string Security)
{
byte[] Value;
UnicodeEncoding Code = new UnicodeEncoding();
byte[] Message = Code.GetBytes(Security);
SHA512Managed Arithmetic = new SHA512Managed();
Value = Arithmetic.ComputeHash(Message);
Security = "";
foreach(byte o in Value)
{
Security = (int) o "O";
}
return Security;
}
}
}
原文鏈接:HashEncode哈希加密算法幫助類庫