You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
669 B
Go
25 lines
669 B
Go
12 months ago
|
package argon2
|
||
|
|
||
|
import (
|
||
|
// Standard
|
||
|
"crypto/rand"
|
||
|
"encoding/base64"
|
||
|
"fmt"
|
||
|
|
||
|
// Standard Extended
|
||
|
"golang.org/x/crypto/argon2"
|
||
|
)
|
||
|
|
||
|
// Hash
|
||
|
func (algorithm Algorithm) Hash(data []byte) (string, error) {
|
||
|
// Generate Salt
|
||
|
salt := make([]byte, algorithm.saltLen)
|
||
|
_, err := rand.Read(salt)
|
||
|
// Handle Error
|
||
|
if err != nil {
|
||
|
return "", err
|
||
|
}
|
||
|
// Hash
|
||
|
return fmt.Sprintf("$argon2id$v=%d$m=%d,t=%d,p=%d$%s$%s", argon2.Version, algorithm.memory, algorithm.time, algorithm.threads, base64.RawStdEncoding.EncodeToString(salt), base64.RawStdEncoding.EncodeToString(argon2.IDKey(data, salt, algorithm.time, algorithm.memory, algorithm.threads, algorithm.keyLen))), err
|
||
|
}
|