将写内容过程重要的内容做个记录,如下的内容段是关于C#得到随机安全码(哈希加密)的封装类的内容,希望能对各位朋友有所用处。
using System;
using System.Text;
using System.Security.Cryptography;
namespace DotNet.Utilities
{
public class HashEncode
{
public HashEncode()
{
}
public static string GetSecurity()
{
string Security = HashEncoding(GetRandomValue());
return Security;
}
public static string GetRandomValue()
{
Random Seed = new Random();
string RandomVaule = Seed.Next(1, int.MaxValue).ToString();
return RandomVaule;
}
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;
}
}
}
网友评论