⚠️ DISCLAIMER:
Use with caution in your Go/Gorilla applications. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
32 BYTE AUTH KEY (HMAC signing key)
e/n+Z7Tp8/iVKpuAvZdlpar5tR/tGsDubHwhlfNXnHxEH4eYTUeT5lQiM7xu8u+s7jcLOk0vHTObBJy1ResloQ==
16 BYTE ENCRYPT KEY (AES-256 encryption key)
mP+w9GrvOVitByogllBbQDBorOxOynbClOkFmjx9rfM=
HOW TO USE IN YOUR CODE
//Somewhere in your .env file
SESSION_AUTH_KEY=e/n+Z7Tp8/iVKpuAvZdlpar5tR/tGsDubHwhlfNXnHxEH4eYTUeT5lQiM7xu8u+s7jcLOk0vHTObBJy1ResloQ==
SESSION_ENCRYPT_KEY=mP+w9GrvOVitByogllBbQDBorOxOynbClOkFmjx9rfM=
/*=== NOTE: Keys are generated as Base64 Encoded. Use the following function to decode and use in your Go code ===*/
//Go code start
import (
"os"
"github.com/gorilla/sessions"
"github.com/joho/godotenv"
"encoding/base64"
)
func getKeyFromEnv(name string) []byte {
raw, err := base64.StdEncoding.DecodeString(os.Getenv(name))
if err != nil {
panic("Invalid base64 for " + name)
}
return raw
}
func init() {
_ = godotenv.Load() // loads from .env file
}
var store = sessions.NewCookieStore(
getKeyFromEnv("SESSION_AUTH_KEY"),
getKeyFromEnv("SESSION_ENCRYPT_KEY"),
)