Fixed some wonky encryption BS
This commit is contained in:
parent
e8e14c988d
commit
32374cfbb4
2 changed files with 13 additions and 5 deletions
|
@ -4,9 +4,9 @@ POSTGRES_PASSWORD=password
|
|||
POSTGRES_USER=username
|
||||
|
||||
# Security
|
||||
ENCRYPTION_KEY="super-secret"
|
||||
SIGNING_KEY="super-secret"
|
||||
AUTH_SECRET="super-secret"
|
||||
ENCRYPTION_KEY="hOzXzSwDSuU41PMtMHm9O/nqf1X+jTB3MOgVDSPXC5o="
|
||||
SIGNING_KEY="hOzXzSwDSuU41PMtMHm9O/nqf1X+jTB3MOgVDSPXC5o="
|
||||
AUTH_SECRET="hOzXzSwDSuU41PMtMHm9O/nqf1X+jTB3MOgVDSPXC5o="
|
||||
|
||||
# Feature Flags
|
||||
DEVMODE=true
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"crypto/aes"
|
||||
"crypto/cipher"
|
||||
"crypto/rand"
|
||||
"crypto/sha256"
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
|
@ -36,9 +37,16 @@ func InitSessionMiddleware() echo.MiddlewareFunc {
|
|||
return session.Middleware(store)
|
||||
}
|
||||
|
||||
// Returns the first 32 bytes of the SHA-256 hash of the ENCRYPTION_KEY environment variable
|
||||
func getEncryptionKey() []byte {
|
||||
key := []byte(os.Getenv("ENCRYPTION_KEY"))
|
||||
hash := sha256.Sum256(key)
|
||||
return hash[:32] // Use the first 32 bytes for AES-256
|
||||
}
|
||||
|
||||
// Encrypt data using AES
|
||||
func encrypt(data []byte) (string, error) {
|
||||
encryptionKey := []byte(os.Getenv("ENCRYPTION_KEY"))
|
||||
encryptionKey := getEncryptionKey()
|
||||
fmt.Printf("Encryption Key Length: %d\n", len(encryptionKey))
|
||||
|
||||
block, err := aes.NewCipher(encryptionKey)
|
||||
|
@ -60,7 +68,7 @@ func encrypt(data []byte) (string, error) {
|
|||
|
||||
// decrypt decrypts the data using AES-GCM.
|
||||
func decrypt(encryptedString string) (string, error) {
|
||||
encryptionKey := []byte(os.Getenv("ENCRYPTION_KEY"))
|
||||
encryptionKey := getEncryptionKey()
|
||||
|
||||
data, err := base64.StdEncoding.DecodeString(encryptedString)
|
||||
if err != nil {
|
||||
|
|
Loading…
Add table
Reference in a new issue