SM3Util.cs 784 B

12345678910111213141516171819202122232425262728
  1. using Org.BouncyCastle.Utilities.Encoders;
  2. namespace Admin.NET.Core;
  3. /// <summary>
  4. /// SM3工具类
  5. /// </summary>
  6. public class SM3Util
  7. {
  8. public string secretKey = "";
  9. public string 加密(string data)
  10. {
  11. byte[] msg1 = Encoding.Default.GetBytes(data);
  12. //byte[] key1 = Encoding.Default.GetBytes(secretKey);
  13. //var keyParameter = new KeyParameter(key1);
  14. var sm3 = new SM3Digest();
  15. //HMac mac = new HMac(sm3); // 带密钥的杂凑算法
  16. //mac.Init(keyParameter);
  17. sm3.BlockUpdate(msg1, 0, msg1.Length);
  18. // byte[] result = new byte[sm3.GetMacSize()];
  19. byte[] result = new byte[sm3.GetDigestSize()];
  20. sm3.DoFinal(result, 0);
  21. return Encoding.ASCII.GetString(Hex.Encode(result));
  22. }
  23. }