[C#] C#得到随机安全码(哈希加密)的封装类 →→→→→进入此内容的聊天室

来自 , 2019-07-15, 写在 C#, 查看 123 次.
URL http://www.code666.cn/view/9d3d9b88
  1. using System;
  2. using System.Text;
  3. using System.Security.Cryptography;
  4. namespace DotNet.Utilities
  5. {
  6.         /// <summary>
  7.         /// 得到随机安全码(哈希加密)。
  8.         /// </summary>
  9.         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.                 /// 哈希加密一个字符串,sharejs.com
  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. }
  57.  
  58. //csharp/8612

回复 "C#得到随机安全码(哈希加密)的封装类"

这儿你可以回复上面这条便签

captcha