package
module
Version:
v0.0.0-...-94d6cc8
Opens a new window with list of versions in this module.
Published: Dec 17, 2025
License: MIT
Opens a new window with license information.
Imports: 13
Opens a new window with list of imports.
Imported by: 0
Opens a new window with list of known importers.
README
¶
httpx
APISign API参数签名验证
-
- rawStr eg: GET http://example.com/hello?n=1&a=2 Key["n","a"]-ASC Sort["a","n"] GetParam(a) a=2&n=1 param key string attaches the methods
-
- other request http method,for Content-Type: application/json {"n":"m","a":2} Key ASC Sort,param key string attaches the methods => {"a":2,"n":"m"} => a=2&n=m
-
- rawStr+timestamp => a=2&n=m1626167650 (1626167650 is unix timestamp), verify sign time valid(default 10s)
-
- Sign Method: Method(rawStr+timestamp, secretKey) signed text encode [Base64, Hex(default)]
// Method=[HMAC-SHA256,HMAC-SHA1] Encode=[Base64,Hex] Default = HMAC-SHA256-HEX
-
- default: signStr=Hex(HMAC-SHA256(rawStr+timestamp,secretKey))
-
- Sign http request Header X-Signature=accessKey:signStr:timestamp (: split elem)
USEAGE
see test example
Documentation
¶
APISign API Param Sign
- rawStr eg: GET http://example.com/hello?n=1&a=2 Key["n","a"]-ASC Sort["a","n"] GetParam(a) a=2&n=1 param key string attaches the methods
- other request http method,for Content-Type: application/json {"n":"m","a":2} Key ASC Sort,param key string attaches the methods => {"a":2,"n":"m"} => a=2&n=m
- rawStr+timestamp => a=2&n=m1626167650 (1626167650 is unix timestamp), verify sign time valid(default 10s)
- Sign Method: Method(rawStr+timestamp, secretKey) signed text encode [Base64, Hex(default)]
Method=[HMAC-SHA256,HMAC-SHA1] Encode=[Base64,Hex] Default = HMAC-SHA256-HEX
- default: signStr=Hex(HMAC-SHA256(rawStr+timestamp,secretKey))
- Sign http request Header X-Signature=accessKey:signStr:timestamp (: split elem)
Sign sign and return signature,deadline is validity period of signature
ToSignRaw 从req解析并生成已排序待签名参数字符串
如果contentType是JSON,只取JSON参数
其他:取URL PARAMS和BODY PARAMS
Verify param sign result verify
req:the http.Request
authHeaderName:header name,like X-Signature,value:accessKey:signature:deadline
type Kv struct {
Key string
Value interface{}
}
const (
HmacSha256 Method = "HMAC-SHA256-BASE64"
HmacSha1 Method = "HMAC-SHA1-BASE64"
HmacSha1Hex Method = "HMAC-SHA1-HEX"
HmacSha256Hex Method = "HMAC-SHA256-HEX"
)
Source Files
¶
Click to show internal directories.
Click to hide internal directories.