C#獲取哈希加密生成隨機(jī)安全碼的類實(shí)例
本文實(shí)例講述了C#獲取哈希加密生成隨機(jī)安全碼的類。分享給大家供大家參考。具體分析如下:
這個(gè)C#類封裝了一些hash加密的功能,可以用于得到隨機(jī)哈希加密字符串使用非常方便
using System; using System.Text; using System.Security.Cryptography; namespace DotNet.Utilities { /// <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è)字符串,sharejs.com /// </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; } } }
希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。
相關(guān)文章

C#啟動(dòng)和停止windows服務(wù)的實(shí)例代碼

C#實(shí)現(xiàn)獲取程序路徑方法小結(jié)

C#設(shè)計(jì)模式之觀察者模式實(shí)例講解

winform 實(shí)現(xiàn)選擇文件和選擇文件夾對(duì)話框的簡(jiǎn)單實(shí)例

C# Entity Framework中的IQueryable和IQueryProvider詳解