sign

package
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 31, 2021 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HmacHash

func HmacHash(method Method, rawStr, secretKey string) string

func HmacSha1ToBase64

func HmacSha1ToBase64(rawStr, key string) string

HmacSha1ToBase64 HMAC-SHA1 签名并BASE64 编码

func HmacSha1ToHex

func HmacSha1ToHex(rawStr, key string) string

HmacSha1ToHex

func HmacSha256ToBase64

func HmacSha256ToBase64(rawStr, key string) string

HmacSha256ToBase64 HMAC-SHA256 签名并BASE64 编码

func HmacSha256ToHex

func HmacSha256ToHex(rawStr, key string) string

HmacSha256ToHex

func SortParamForm

func SortParamForm(req *http.Request, path bool) (string, error)

SortParamForm URL 和 form-data 参数

Types

type APISign

type APISign struct {
	// contains filtered or unexported fields
}

1. 签名头X-Signature=accessKey:signStr:timestamp (:分割不同元素) 2. 签名方式: Method(rawStr+timestamp, secretKey) 最终signStr是Base64编码 3. rawStr 解释 如果是 GET请求,例子: http://example.com/hello?n=1&a=2 => /hello?a=2&n=11626167650 参数要进行字符正序 4. 非GET请求,对于Content-Type: application/json {"n":"m","a":2} 也进行字符正序 => {"a":2,"n":"m"} 最终 a=2&n=m 5. rawStr+timestamp = /hello?a=2&n=m1626167650 时间戳(秒) 最终在签名,携带时间戳,是为了验证签名时间有效性 当前有效性 -+10s 6. 最终形式都是 path?/k=v&k1=v1 + timestamp

APISign 接口签名

func NewAPISign

func NewAPISign(signValidDuration time.Duration, method Method) *APISign

signValidDuration sign valid time interval

func (*APISign) SetGetSecretKey

func (sign *APISign) SetGetSecretKey(f func(accessKey string) (string, error))

SetGetSecretKey 设置SecretKey 获取方法

func (*APISign) Verify

func (sign *APISign) Verify(req *http.Request, header string) error

Verify 验证签名

type Kv

type Kv struct {
	Key   string
	Value interface{}
}

type KvSlice

type KvSlice []Kv

func (KvSlice) Len

func (s KvSlice) Len() int

func (KvSlice) Less

func (s KvSlice) Less(i, j int) bool

func (KvSlice) Swap

func (s KvSlice) Swap(i, j int)

type Method

type Method string
const (
	HmacSha256 Method = "HMAC-SHA256"
	HmacSha1   Method = "HMAC-SHA1"
)

type RequestBodyMap

type RequestBodyMap map[string]interface{}

func (RequestBodyMap) GetStringValue

func (r RequestBodyMap) GetStringValue(key string) (string, error)

func (RequestBodyMap) SortToString

func (r RequestBodyMap) SortToString(separator string) (string, error)

func (RequestBodyMap) TrimNewline

func (r RequestBodyMap) TrimNewline(buf []byte) []byte

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL