Admin.net框架
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

28 lines
784 B

using Org.BouncyCastle.Utilities.Encoders;
namespace Admin.NET.Core;
/// <summary>
/// SM3工具类
/// </summary>
public class SM3Util
{
public string secretKey = "";
public string (string data)
{
byte[] msg1 = Encoding.Default.GetBytes(data);
//byte[] key1 = Encoding.Default.GetBytes(secretKey);
//var keyParameter = new KeyParameter(key1);
var sm3 = new SM3Digest();
//HMac mac = new HMac(sm3); // 带密钥的杂凑算法
//mac.Init(keyParameter);
sm3.BlockUpdate(msg1, 0, msg1.Length);
// byte[] result = new byte[sm3.GetMacSize()];
byte[] result = new byte[sm3.GetDigestSize()];
sm3.DoFinal(result, 0);
return Encoding.ASCII.GetString(Hex.Encode(result));
}
}