Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetHash ¶ added in v1.1.0
SetHash set a global hash function for signed cookies, default to:
func(key, data string) []byte { h := hmac.New(sha1.New, []byte(key)) h.Write([]byte(data)) return h.Sum(nil) }
The default hash is for compatibility with https://github.com/pillarjs/cookies But it is easy to crack secret key. You should set a custom hash function, such as:
func(key, data string) []byte { h := hmac.New(sha256.New, []byte(key)) h.Write([]byte(data)) h.Write(salt) // some salt bytes return h.Sum(nil) }
Types ¶
type Cookies ¶
type Cookies struct {
// contains filtered or unexported fields
}
Cookies manipulates http.Cookie easy, supports signed cookies.
func (*Cookies) Get ¶
Get returns the cookie with the given name from the Cookie header in the request. If such a cookie exists, its value is returned. Otherwise, nothing is returned. signed = true can optionally be passed as the second parameter. In this case, a signature cookie (a cookie of same name ending with the .sig suffix appended) is fetched. If the signature cookie does exist, cookie will check the hash of cookie-value whether matches registered keys.