63 lines
1.7 KiB
C#
63 lines
1.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Runtime.Serialization.Json;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using System.Web.Services.Protocols;
|
|
using System.Security.Cryptography;
|
|
using System.Text;
|
|
using System.Web.SessionState;
|
|
using System.Data;
|
|
using System.Drawing.Imaging;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
using System.Data.SqlClient;
|
|
using System.Configuration;
|
|
|
|
public static class globalClass
|
|
{
|
|
public static string CreateRandomCode(int Number)
|
|
{
|
|
string allChar = "0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z";
|
|
string[] allCharArray = allChar.Split(',');
|
|
string randomCode = "";
|
|
|
|
Random rand = new Random(Guid.NewGuid().GetHashCode());
|
|
for (int i = 0; i <= Number - 1; i++)
|
|
{
|
|
int t = rand.Next(allCharArray.Length);
|
|
randomCode += allCharArray[t];
|
|
}
|
|
return randomCode;
|
|
}
|
|
|
|
public static string appsettings(string key)
|
|
{
|
|
|
|
return ConfigurationManager.ConnectionStrings[key].ConnectionString;
|
|
}
|
|
|
|
public static string SHA256_Encode(string value)
|
|
{
|
|
byte[] bytValue = System.Text.Encoding.UTF8.GetBytes(value);
|
|
try
|
|
{
|
|
SHA256 sha256 = new SHA256CryptoServiceProvider();
|
|
byte[] retVal = sha256.ComputeHash(bytValue);
|
|
StringBuilder sb = new StringBuilder();
|
|
for (int i = 0; i < retVal.Length; i++)
|
|
{
|
|
sb.Append(retVal[i].ToString("x2"));
|
|
}
|
|
return sb.ToString();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception("GetSHA256HashFromString() fail,error:" + ex.Message);
|
|
}
|
|
|
|
}
|
|
|
|
} |