C Gets a class instance that generates a random security code with hash encryption
- 2021-01-25 07:52:09
- OfStack
This article illustrates C#'s class for getting hash encryption to generate random security codes. Share with you for your reference. The specific analysis is as follows:
This C# class encapsulates some of the hash encryption features and is very handy for getting random hash encrypted strings
using System;
using System.Text;
using System.Security.Cryptography;
namespace DotNet.Utilities
{
/// <summary>
/// Get a random security code (hash encryption).
/// </summary>
public class HashEncode
{
public HashEncode()
{
//
// TODO: Add the constructor logic here
//
}
/// <summary>
/// Get a random hash encrypted string
/// </summary>
/// <returns></returns>
public static string GetSecurity()
{
string Security = HashEncoding(GetRandomValue());
return Security;
}
/// <summary>
/// get 1 Random values
/// </summary>
/// <returns></returns>
public static string GetRandomValue()
{
Random Seed = new Random();
string RandomVaule = Seed.Next(1, int.MaxValue).ToString();
return RandomVaule;
}
/// <summary>
/// Hash encryption 1 A string, 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;
}
}
}
I hope this article is helpful to your C# programming.