45 lines
1.3 KiB
C#
45 lines
1.3 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Security.Cryptography;
|
|||
|
|
using System.Text;
|
|||
|
|
|
|||
|
|
namespace SAL_OUTSTOCK.Utils
|
|||
|
|
{
|
|||
|
|
internal static class SHA256Helper
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// SHA256加密
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="data"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public static string SHA256EncryptString(string data)
|
|||
|
|
{
|
|||
|
|
byte[] bytes = Encoding.UTF8.GetBytes(data);
|
|||
|
|
byte[] hash = SHA256Managed.Create().ComputeHash(bytes);
|
|||
|
|
|
|||
|
|
StringBuilder builder = new StringBuilder();
|
|||
|
|
for (int i = 0; i < hash.Length; i++)
|
|||
|
|
{
|
|||
|
|
builder.Append(hash[i].ToString("x2"));
|
|||
|
|
}
|
|||
|
|
return builder.ToString();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// SHA256加密
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="StrIn">待加密字符串</param>
|
|||
|
|
/// <returns>加密数组</returns>
|
|||
|
|
public static Byte[] SHA256EncryptByte(string StrIn)
|
|||
|
|
{
|
|||
|
|
var sha256 = new SHA256Managed();
|
|||
|
|
var Asc = new ASCIIEncoding();
|
|||
|
|
var tmpByte = Asc.GetBytes(StrIn);
|
|||
|
|
var EncryptBytes = sha256.ComputeHash(tmpByte);
|
|||
|
|
sha256.Clear();
|
|||
|
|
return EncryptBytes;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|