sign

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2022 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeHeaderVal added in v0.1.3

func DecodeHeaderVal(headerVal string) (accessKey, signStr, timestamp string, err error)

DecodeHeaderVal header value decode to accessKey:signStr:timestamp

func HmacHash

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

func HmacSha1ToBase64

func HmacSha1ToBase64(rawStr, key string) string

HmacSha1ToBase64 HMAC-SHA1

func HmacSha1ToHex

func HmacSha1ToHex(rawStr, key string) string

HmacSha1ToHex

func HmacSha256ToBase64

func HmacSha256ToBase64(rawStr, key string) string

HmacSha256ToBase64 HMAC-SHA256

func HmacSha256ToHex

func HmacSha256ToHex(rawStr, key string) string

HmacSha256ToHex

func SignedValidTime added in v0.1.3

func SignedValidTime(t time.Time) error

func SortParamForm

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

SortParamForm URL and form-data param

Types

type APISign

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

1. Sign Header Key = X-Signature Value = accessKey:signStr:timestamp (: split elem) 2. Sign Method: Method(rawStr+timestamp, secretKey) signStr(rawStr+timestamp) => encoding Base64 | Hex(default) 3. rawStr eg: GET http://example.com/hello?n=1&a=2 => a=2&n=11626167650 param key string attaches the methods 4. other request http method,for Content-Type: application/json {"n":"m","a":2} param key string attaches the methods => {"a":2,"n":"m"} => a=2&n=m 5. rawStr+timestamp => a=2&n=m1626167650 timestamp(sec) verify sign time valid(default 10s) 6. if Config.PathSign = true URL.Path also need to sign, rawStr => /path?k=v&k1=v1 , default Config.PathSign = false

APISign API Sign

func NewAPISign

func NewAPISign(cfg *Config) *APISign

signValidDuration sign valid time interval

func (*APISign) SetGetSecretKey

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

SetGetSecretKey setting SecretKey get function

func (*APISign) Verify

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

Verify sign verify

type Config added in v0.1.0

type Config struct {
	SignValidDuration time.Duration `defval:"10s"`
	Method            `defval:"HMAC-SHA256-HEX"`
	PathSign          bool `defval:"false"`
}

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-BASE64"
	HmacSha1      Method = "HMAC-SHA1-BASE64"
	HmacSha1Hex   Method = "HMAC-SHA1-HEX"
	HmacSha256Hex Method = "HMAC-SHA256-HEX"
)

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