IT_컴퓨터_코딩_개발

[GoLang] gorilla securecookie example

파워유저 2016. 10. 17. 21:43

gorilla securecookie Encode/Decode example

 

func main() {
    _cookie := ""

    {
        var hashKey = []byte("very-secret_very-secret_very-secret_very-secret")
        var blockKey = []byte("a-lot-secret-123")
        var s = securecookie.New(hashKey, blockKey)

        orgvalue := map[string]string{"MYKEY": "MYVALUE"}
        cookie, err := s.Encode("cookie-name", orgvalue)
        if err != nil {
            panic(err)
        }

        fmt.Println("cookie:", cookie)
        _cookie = cookie
    }

    {
        var hashKey = []byte("very-secret_very-secret_very-secret_very-secret")
        var blockKey = []byte("a-lot-secret-123")
        var s = securecookie.New(hashKey, blockKey)

        dest := map[string]string{}
        err := s.Decode("cookie-name", _cookie, &dest)
        if err != nil {
            panic(err)
        }

        fmt.Println("dest:", dest, dest["MYKEY"])
    }
}