chore(tfstated): refactor helpers to their own package

This commit is contained in:
Julien Dessaux 2024-11-17 00:05:22 +01:00
parent 5b6da56089
commit 25ed1188ed
Signed by: adyxax
GPG key ID: F92E51B86E07177E
11 changed files with 78 additions and 62 deletions

21
pkg/helpers/crypto.go Normal file
View file

@ -0,0 +1,21 @@
package helpers
import (
"crypto/sha256"
"git.adyxax.org/adyxax/tfstated/pkg/scrypto"
"golang.org/x/crypto/pbkdf2"
)
const (
PBKDF2Iterations = 600000
SaltSize = 32
)
func GenerateSalt() []byte {
return scrypto.RandomBytes(SaltSize)
}
func HashPassword(password string, salt []byte) []byte {
return pbkdf2.Key([]byte(password), salt, PBKDF2Iterations, 32, sha256.New)
}