mirror of
https://github.com/mickael-kerjean/filestash
synced 2025-12-07 17:02:29 +01:00
feature (middleware): expose gcm encrypt to templating
This commit is contained in:
parent
da20ac8b70
commit
ae0eb94c61
2 changed files with 6 additions and 2 deletions
|
|
@ -30,7 +30,7 @@ func EncryptString(secret string, data string) (string, error) {
|
|||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
d, err = encrypt([]byte(secret), d)
|
||||
d, err = EncryptAESGCM([]byte(secret), d)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
@ -126,7 +126,7 @@ func QuickString(n int) string {
|
|||
return string(b)
|
||||
}
|
||||
|
||||
func encrypt(key []byte, plaintext []byte) ([]byte, error) {
|
||||
func EncryptAESGCM(key []byte, plaintext []byte) ([]byte, error) {
|
||||
c, err := aes.NewCipher(key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
|||
|
|
@ -382,6 +382,10 @@ func SessionAuthMiddleware(ctx *App, res http.ResponseWriter, req *http.Request)
|
|||
}
|
||||
return false
|
||||
},
|
||||
"encryptGCM": func(str string, key string) (string, error) {
|
||||
data, err := EncryptAESGCM([]byte(key), []byte(str))
|
||||
return base64.StdEncoding.EncodeToString(data), err
|
||||
},
|
||||
}).
|
||||
Parse(str)
|
||||
mappingToUse[k] = str
|
||||
|
|
|
|||
Loading…
Reference in a new issue