38 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
		
		
			
		
	
	
			38 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| 
								 | 
							
								using System.Security.Cryptography;
							 | 
						|||
| 
								 | 
							
								using System.Text;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								namespace APT.Utility
							 | 
						|||
| 
								 | 
							
								{
							 | 
						|||
| 
								 | 
							
								    public static partial class PolyvSignatureHelper
							 | 
						|||
| 
								 | 
							
								    {
							 | 
						|||
| 
								 | 
							
								        /// <summary>
							 | 
						|||
| 
								 | 
							
								        /// 生成保利威API所需的SHA1签名
							 | 
						|||
| 
								 | 
							
								        /// </summary>
							 | 
						|||
| 
								 | 
							
								        /// <param name="secretKey">保利威提供的secretkey</param>
							 | 
						|||
| 
								 | 
							
								        /// <param name="paramsStr">参与签名的参数字符串</param>
							 | 
						|||
| 
								 | 
							
								        /// <returns>SHA1签名结果</returns>
							 | 
						|||
| 
								 | 
							
								        public static string GenerateSha1Signature(string signStr)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            // 1. 将secretkey和参数字符串拼接
							 | 
						|||
| 
								 | 
							
								            //string signStr = secretKey + paramsStr;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								            // 2. 创建SHA1实例
							 | 
						|||
| 
								 | 
							
								            using (SHA1 sha1 = SHA1.Create())
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                // 3. 将字符串转换为字节数组
							 | 
						|||
| 
								 | 
							
								                byte[] bytes = Encoding.UTF8.GetBytes(signStr);
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								                // 4. 计算哈希值
							 | 
						|||
| 
								 | 
							
								                byte[] hashBytes = sha1.ComputeHash(bytes);
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								                // 5. 将字节数组转换为十六进制字符串
							 | 
						|||
| 
								 | 
							
								                StringBuilder sb = new StringBuilder();
							 | 
						|||
| 
								 | 
							
								                foreach (byte b in hashBytes)
							 | 
						|||
| 
								 | 
							
								                {
							 | 
						|||
| 
								 | 
							
								                    sb.AppendFormat("{0:x2}", b);
							 | 
						|||
| 
								 | 
							
								                }
							 | 
						|||
| 
								 | 
							
								                return sb.ToString().ToUpper();
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								    }
							 | 
						|||
| 
								 | 
							
								}
							 |