main.go 942 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package main
  2. import (
  3. "encoding/base64"
  4. "fmt"
  5. "log"
  6. "github.com/ente-io/museum/pkg/utils/auth"
  7. generichash "github.com/GoKillers/libsodium-go/cryptogenerichash"
  8. secretbox "github.com/GoKillers/libsodium-go/cryptosecretbox"
  9. "github.com/GoKillers/libsodium-go/sodium"
  10. )
  11. func main() {
  12. sodium.Init()
  13. keyBytes, err := auth.GenerateRandomBytes(secretbox.CryptoSecretBoxKeyBytes())
  14. if err != nil {
  15. log.Fatal(err)
  16. }
  17. key := base64.StdEncoding.EncodeToString(keyBytes)
  18. hashBytes, err := auth.GenerateRandomBytes(generichash.CryptoGenericHashBytesMax())
  19. if err != nil {
  20. log.Fatal(err)
  21. }
  22. hash := base64.StdEncoding.EncodeToString(hashBytes)
  23. jwtBytes, err := auth.GenerateRandomBytes(secretbox.CryptoSecretBoxKeyBytes())
  24. if err != nil {
  25. log.Fatal(err)
  26. }
  27. jwt := base64.URLEncoding.EncodeToString(jwtBytes)
  28. fmt.Printf("key.encryption: %s\n", key)
  29. fmt.Printf("key.hash: %s\n", hash)
  30. fmt.Printf("jwt.secret: %s\n", jwt)
  31. }