/// <summary> /// sm3加密(使用自定义Hex密钥) /// </summary> /// <param name="data"></param> /// <param name="key"></param> /// <returns></returns> public static string ToSM3HexStr(string data, string key) { byte[] msg1 = Encoding.Default.GetBytes(data); byte[] key1 = System.Text.Encoding.UTF8.GetBytes(key); KeyParameter keyParameter = new KeyParameter(key1); SM3Digest sm3 = new SM3Digest(); HMac mac = new HMac(sm3);//带密钥的杂凑算法 mac.Init(keyParameter); mac.BlockUpdate(msg1, 0, msg1.Length); byte[] result = new byte[mac.GetMacSize()]; mac.DoFinal(result, 0); return(new UTF8Encoding().GetString(Hex.Encode(result))); }