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
|
POSTGRES_USER=username
|
||||||
|
|
||||||
# Security
|
# Security
|
||||||
ENCRYPTION_KEY="super-secret"
|
ENCRYPTION_KEY="hOzXzSwDSuU41PMtMHm9O/nqf1X+jTB3MOgVDSPXC5o="
|
||||||
SIGNING_KEY="super-secret"
|
SIGNING_KEY="hOzXzSwDSuU41PMtMHm9O/nqf1X+jTB3MOgVDSPXC5o="
|
||||||
AUTH_SECRET="super-secret"
|
AUTH_SECRET="hOzXzSwDSuU41PMtMHm9O/nqf1X+jTB3MOgVDSPXC5o="
|
||||||
|
|
||||||
# Feature Flags
|
# Feature Flags
|
||||||
DEVMODE=true
|
DEVMODE=true
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"crypto/aes"
|
"crypto/aes"
|
||||||
"crypto/cipher"
|
"crypto/cipher"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
|
"crypto/sha256"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
@ -36,9 +37,16 @@ func InitSessionMiddleware() echo.MiddlewareFunc {
|
||||||
return session.Middleware(store)
|
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
|
// Encrypt data using AES
|
||||||
func encrypt(data []byte) (string, error) {
|
func encrypt(data []byte) (string, error) {
|
||||||
encryptionKey := []byte(os.Getenv("ENCRYPTION_KEY"))
|
encryptionKey := getEncryptionKey()
|
||||||
fmt.Printf("Encryption Key Length: %d\n", len(encryptionKey))
|
fmt.Printf("Encryption Key Length: %d\n", len(encryptionKey))
|
||||||
|
|
||||||
block, err := aes.NewCipher(encryptionKey)
|
block, err := aes.NewCipher(encryptionKey)
|
||||||
|
@ -60,7 +68,7 @@ func encrypt(data []byte) (string, error) {
|
||||||
|
|
||||||
// decrypt decrypts the data using AES-GCM.
|
// decrypt decrypts the data using AES-GCM.
|
||||||
func decrypt(encryptedString string) (string, error) {
|
func decrypt(encryptedString string) (string, error) {
|
||||||
encryptionKey := []byte(os.Getenv("ENCRYPTION_KEY"))
|
encryptionKey := getEncryptionKey()
|
||||||
|
|
||||||
data, err := base64.StdEncoding.DecodeString(encryptedString)
|
data, err := base64.StdEncoding.DecodeString(encryptedString)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Add table
Reference in a new issue