diff options
author | Julien Dessaux | 2024-11-17 00:05:22 +0100 |
---|---|---|
committer | Julien Dessaux | 2024-12-17 23:19:18 +0100 |
commit | 25ed1188ed970a19675befef12afe68045565c4a (patch) | |
tree | 5cfc55047d833400028fb69a7f069f5cedecaacd /pkg/helpers/crypto.go | |
parent | fix(tfstated): hash passwords instead of relying on the database encryption key (diff) | |
download | tfstated-25ed1188ed970a19675befef12afe68045565c4a.tar.gz tfstated-25ed1188ed970a19675befef12afe68045565c4a.tar.bz2 tfstated-25ed1188ed970a19675befef12afe68045565c4a.zip |
chore(tfstated): refactor helpers to their own package
Diffstat (limited to 'pkg/helpers/crypto.go')
-rw-r--r-- | pkg/helpers/crypto.go | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/pkg/helpers/crypto.go b/pkg/helpers/crypto.go new file mode 100644 index 0000000..ce73cd3 --- /dev/null +++ b/pkg/helpers/crypto.go @@ -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) +} |