mirror of
https://github.com/mickael-kerjean/filestash
synced 2025-12-06 08:22:24 +01:00
feature (tmpl): additional template func
This commit is contained in:
parent
f412c467b3
commit
4b02bb00ef
2 changed files with 15 additions and 3 deletions
|
|
@ -41,7 +41,7 @@ func DecryptString(secret string, data string) (string, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
d, err = decrypt([]byte(secret), d)
|
d, err = DecryptAESGCM([]byte(secret), d)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
@ -143,7 +143,7 @@ func EncryptAESGCM(key []byte, plaintext []byte) ([]byte, error) {
|
||||||
return gcm.Seal(nonce, nonce, plaintext, nil), nil
|
return gcm.Seal(nonce, nonce, plaintext, nil), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func decrypt(key []byte, ciphertext []byte) ([]byte, error) {
|
func DecryptAESGCM(key []byte, ciphertext []byte) ([]byte, error) {
|
||||||
c, err := aes.NewCipher(key)
|
c, err := aes.NewCipher(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
||||||
|
|
@ -115,7 +115,19 @@ var tmplFuncs = template.FuncMap{
|
||||||
}
|
}
|
||||||
return strings.Join(chunks, ", "), nil
|
return strings.Join(chunks, ", "), nil
|
||||||
},
|
},
|
||||||
"encryptGCM": func(str string, key string) (string, error) {
|
"debug": func(data string) (string, error) {
|
||||||
|
Log.Debug("ctrl/tmpl data=%s", data)
|
||||||
|
return data, nil
|
||||||
|
},
|
||||||
|
"decryptGCM": func(key string, str string) (string, error) {
|
||||||
|
t, err := base64.StdEncoding.DecodeString(str)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
d, err := DecryptAESGCM([]byte(key), t)
|
||||||
|
return string(d), err
|
||||||
|
},
|
||||||
|
"encryptGCM": func(key string, str string) (string, error) {
|
||||||
data, err := EncryptAESGCM([]byte(key), []byte(str))
|
data, err := EncryptAESGCM([]byte(key), []byte(str))
|
||||||
return base64.StdEncoding.EncodeToString(data), err
|
return base64.StdEncoding.EncodeToString(data), err
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue