mirror of
https://github.com/number571/go-peer.git
synced 2026-09-12 19:50:00 +05:00
34 lines
511 B
Go
34 lines
511 B
Go
package keybuilder
|
|
|
|
import (
|
|
"crypto/sha512"
|
|
|
|
"golang.org/x/crypto/pbkdf2"
|
|
)
|
|
|
|
var (
|
|
_ IKeyBuilder = &sKeyBuilder{}
|
|
)
|
|
|
|
type sKeyBuilder struct {
|
|
fIterN uint64
|
|
fSalt []byte
|
|
}
|
|
|
|
func NewKeyBuilder(pIterN uint64, pSalt []byte) IKeyBuilder {
|
|
return &sKeyBuilder{
|
|
fIterN: pIterN,
|
|
fSalt: pSalt,
|
|
}
|
|
}
|
|
|
|
func (p *sKeyBuilder) Build(pPassword string, pKeyLen uint64) []byte {
|
|
return pbkdf2.Key(
|
|
[]byte(pPassword),
|
|
p.fSalt,
|
|
int(p.fIterN), //nolint:gosec
|
|
int(pKeyLen), //nolint:gosec
|
|
sha512.New,
|
|
)
|
|
}
|