mirror of
https://github.com/mickael-kerjean/filestash.git
synced 2025-10-28 12:16:48 +08:00
feature (middleware): expose gcm encrypt to templating
This commit is contained in:
@ -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
|
||||
|
||||
Reference in New Issue
Block a user