mirror of
https://github.com/grafana/grafana.git
synced 2025-08-02 16:42:26 +08:00
Chore: additional check when decrypting values (#34637)
* Chore: additional check when decrypting values * Apply suggestions from code review
This commit is contained in:

committed by
GitHub

parent
ab26c4dfa4
commit
a5082ab112
@ -6,6 +6,7 @@ import (
|
||||
"crypto/rand"
|
||||
"crypto/sha256"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"golang.org/x/crypto/pbkdf2"
|
||||
@ -15,6 +16,9 @@ const saltLength = 8
|
||||
|
||||
// Decrypt decrypts a payload with a given secret.
|
||||
func Decrypt(payload []byte, secret string) ([]byte, error) {
|
||||
if len(payload) < saltLength {
|
||||
return nil, fmt.Errorf("unable to compute salt")
|
||||
}
|
||||
salt := payload[:saltLength]
|
||||
key, err := encryptionKeyToBytes(secret, string(salt))
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user