Skip to content

Commit

Permalink
Make the hash function common
Browse files Browse the repository at this point in the history
  • Loading branch information
nakabonne committed Dec 19, 2020
1 parent 87286c2 commit efbe459
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions crypto/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ const (
keyLength = 32
)

var hashFunc = sha256.New

func Encrypt(password string, salt, data []byte) ([]byte, error) {
key := pbkdf2.Key([]byte(password), salt, defaultIterationCount, keyLength, sha256.New)
key := pbkdf2.Key([]byte(password), salt, defaultIterationCount, keyLength, hashFunc)

block, err := aes.NewCipher(key)
if err != nil {
Expand All @@ -37,7 +39,7 @@ func Encrypt(password string, salt, data []byte) ([]byte, error) {
}

func Decrypt(password string, salt, encryptedData []byte) ([]byte, error) {
key := pbkdf2.Key([]byte(password), salt, defaultIterationCount, keyLength, sha256.New)
key := pbkdf2.Key([]byte(password), salt, defaultIterationCount, keyLength, hashFunc)

block, err := aes.NewCipher(key)
if err != nil {
Expand Down

0 comments on commit efbe459

Please # to comment.