Java to C# Method Conversion: Request Header Generation with HMAC-SHA1 Signature
{"title":"Java to C# Method Conversion: Request Header Generation with HMAC-SHA1 Signature", "description":"This article demonstrates the conversion of a Java method for generating a request header with an HMAC-SHA1 signature into its equivalent C# version. The code utilizes the HmacUtils library for calculating the signature and includes detailed explanations of the code changes.", "keywords":"Java, C#, method conversion, request header, HMAC-SHA1, signature, HmacUtils, DateTimeOffset, ToUnixTimeMilliseconds, StringBuilder, appKey, appSecret", "content":"public static String requestHeader(String appKey, String appSecret) {\n long timestamp = System.currentTimeMillis();\n StringBuilder head = new StringBuilder();\n String signature = new HmacUtils(HmacAlgorithms.HMAC_SHA_1, appSecret).hmacHex(appKey + timestamp);\n head.append(appKey).append(SEPARATOR).append(timestamp).append(SEPARATOR).append(signature);\n return head.toString();\n } 从Java方法转换成C#版本的方法内容:public static string RequestHeader(string appKey, string appSecret)\n{\n long timestamp = DateTimeOffset.Now.ToUnixTimeMilliseconds();\n StringBuilder head = new StringBuilder();\n string signature = new HmacUtils(HmacAlgorithms.HmacSha1, appSecret).HmacHex(appKey + timestamp);\n head.Append(appKey).Append(SEPARATOR).append(timestamp).append(SEPARATOR).append(signature);\n return head.ToString();\n}
原文地址: https://www.cveoy.top/t/topic/psFZ 著作权归作者所有。请勿转载和采集!