encryption_go/encryption.go
insanity@loafle.com 167cb6268d .
2017-04-13 12:04:23 +09:00

29 lines
449 B
Go

package encryption
import (
"crypto/rand"
"golang.org/x/crypto/scrypt"
"io"
)
const (
PW_SALT_BYTES = 32
PW_HASH_BYTES = 64
)
func Encrypt(pw string) ([]byte, []byte, error) {
salt := make([]byte, PW_SALT_BYTES)
_, err := io.ReadFull(rand.Reader, salt)
if err != nil {
return nil, nil, err
}
hash, err := scrypt.Key([]byte(pw), salt, 16384, 8, 1, PW_HASH_BYTES)
if err != nil {
return nil, nil, err
}
return salt, hash, nil
}