HashEncode哈希加密算法帮助类库
哈希加密一个字符串
得到随机哈希加密字符串
01 | using System; |
02 | using System.Text; |
03 | using System.Security.Cryptography; |
04 | namespace JsonsHashEncode |
05 | { |
06 | /// <summary> |
07 | /// 得到随机安全码(哈希加密)。 |
08 | /// </summary> |
09 | public class HashEncode |
10 | { |
11 | public HashEncode() |
12 | { |
13 | // |
14 | // TODO: 在此处添加构造函数逻辑 |
15 | // |
16 | } |
17 | /// <summary> |
18 | /// 得到随机哈希加密字符串 |
19 | /// </summary> |
20 | /// <returns></returns> |
21 | public static string GetSecurity() |
22 | { |
23 | string Security = HashEncoding(GetRandomValue()); |
24 | return Security; |
25 | } |
26 | /// <summary> |
27 | /// 得到一个随机数值 |
28 | /// </summary> |
29 | /// <returns></returns> |
30 | public static string GetRandomValue() |
31 | { |
32 | Random Seed = new Random(); |
33 | string RandomVaule = Seed.Next(1, int .MaxValue).ToString(); |
34 | return RandomVaule; |
35 | } |
36 | /// <summary> |
37 | /// 哈希加密一个字符串 |
38 | /// </summary> |
39 | /// <param name="Security"></param> |
40 | /// <returns></returns> |
41 | public static string HashEncoding( string Security) |
42 | { |
43 | byte [] Value; |
44 | UnicodeEncoding Code = new UnicodeEncoding(); |
45 | byte [] Message = Code.GetBytes(Security); |
46 | SHA512Managed Arithmetic = new SHA512Managed(); |
47 | Value = Arithmetic.ComputeHash(Message); |
48 | Security = "" ; |
49 | foreach ( byte o in Value) |
50 | { |
51 | Security = ( int ) o "O" ; |
52 | } |
53 | return Security; |
54 | } |
55 | } |
56 | } |
原文链接:HashEncode哈希加密算法帮助类库