secucookiedump/secucookiedump.go
2024-07-15 21:28:20 -04:00

54 lines
1021 B
Go

package main
import (
"bufio"
"fmt"
"os"
"strings"
"github.com/gorilla/securecookie"
)
func main() {
scanner := bufio.NewScanner(os.Stdin)
key := os.Getenv("SESSION_SECRET")
if key == "" {
fmt.Print("Key not set\nEnter key: ")
for scanner.Scan() {
key = scanner.Text()
if key != "" {
break
}
fmt.Print("Enter key: ")
}
}
s := securecookie.New([]byte(key), nil)
fmt.Println("Using key:", key)
fmt.Println("Enter secure cookie (Ctrl+D to finish):")
for scanner.Scan() {
text := scanner.Text()
fmt.Println("Read:", text)
split := strings.SplitN(text, "=", 2)
//split := strings.Fields(text)
value := make(map[interface{}]interface{})
if err := s.Decode(split[0], split[1], &value); err == nil {
for key, val := range value {
fmt.Printf("Key: %s, Value: %s\n", key, val)
}
} else {
fmt.Println(err)
}
fmt.Println("")
}
if err := scanner.Err(); err != nil {
fmt.Println("Error reading standard input:", err)
}
fmt.Println("Program finished.")
}