Update password hash stuff, totp impl
Some checks are pending
/ test (push) Waiting to run

Move password encryption to argon2id
This commit is contained in:
Melody Becker 2025-03-31 17:40:12 +02:00
parent c1611114d0
commit c269db5b02
Signed by: mstar
SSH key fingerprint: SHA256:9VAo09aaVNTWKzPW7Hq2LW+ox9OdwmTSHRoD4mlz1yI
5 changed files with 201 additions and 3 deletions

65
storage-new/helpers.go Normal file
View file

@ -0,0 +1,65 @@
package storage
import (
"crypto/aes"
"crypto/cipher"
"crypto/rand"
)
// Copied and adjusted from: https://bruinsslot.jp/post/golang-crypto/
func Encrypt(key, data []byte) ([]byte, error) {
// key, salt, err := DeriveKey(key, nil)
// if err != nil {
// return nil, err
// }
//
blockCipher, err := aes.NewCipher(key)
if err != nil {
return nil, err
}
gcm, err := cipher.NewGCM(blockCipher)
if err != nil {
return nil, err
}
nonce := make([]byte, gcm.NonceSize())
if _, err = rand.Read(nonce); err != nil {
return nil, err
}
ciphertext := gcm.Seal(nonce, nonce, data, nil)
// ciphertext = append(ciphertext, salt...)
return ciphertext, nil
}
func Decrypt(key, data []byte) ([]byte, error) {
// salt, data := data[len(data)-32:], data[:len(data)-32]
// key, _, err := DeriveKey(key, salt)
// if err != nil {
// return nil, err
// }
//
blockCipher, err := aes.NewCipher(key)
if err != nil {
return nil, err
}
gcm, err := cipher.NewGCM(blockCipher)
if err != nil {
return nil, err
}
nonce, ciphertext := data[:gcm.NonceSize()], data[gcm.NonceSize():]
plaintext, err := gcm.Open(nil, nonce, ciphertext, nil)
if err != nil {
return nil, err
}
return plaintext, nil
}