在应用别人接口的时候,总是要用签名,很是不理解签名这是怎么知道做的。通过对Attribute的学习了解。大体可以用Attribute来做签名应用。

具体过程如下:

首先我们要先定义一个类,该类继承Attribute。该类主要最用是,签名需要用到的方法、参数和获取加密文件

 1  public class CashiSongAttribute : Attribute
 2     {
 3         /// <summary>
 4         /// 签名参数
 5         /// </summary>
 6         public string[] Param { get; set; }
 7         /// <summary>
 8         /// 是否签名
 9         /// </summary>
10         public bool IsSign { get; set; }
11         /// <summary>
12         /// 加密文件
13         /// </summary>
14         /// <param name="bp"></param>
15         /// <param name="mi"></param>
16         /// <returns></returns>
17         public string ParamEncryption(BasePage bp,System.Reflection.MethodInfo mi)
18         {
19             if (Param != null && Param.Length > 0)
20             {
21                 string md5 = "op" + mi.Name.ToLower();
22                 foreach (string item in Param)
23                 {
24                     if (item.ToLower() == "op" || item.ToLower() == "sign")
25                         continue;
26                     md5 += item + bp.GetRequest(item);
27                 }
28                 byte[] bytestr = Encoding.Default.GetBytes(md5);
29                 MD5 _md5 = new MD5CryptoServiceProvider();
30                 byte[] bytesend = _md5.ComputeHash(bytestr);
31                 return BitConverter.ToString(bytesend).Replace("-", "");
32             }
33             return "";
34         }
35     }
View Code

相关文章:

  • 2021-12-02
  • 2021-08-01
  • 2021-04-12
  • 2021-10-07
  • 2021-09-29
  • 2022-12-23
  • 2021-12-02
猜你喜欢
  • 2021-09-08
  • 2022-12-23
  • 2021-09-16
  • 2021-06-14
  • 2022-12-23
  • 2021-10-13
相关资源
相似解决方案