mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-22 03:08:38 +00:00
feat: add crypto pkg
This commit is contained in:
27
internal/crypto/bcrypt.go
Normal file
27
internal/crypto/bcrypt.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package crypto
|
||||
|
||||
import (
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
var _ HashAlg = (*BCrypt)(nil)
|
||||
|
||||
type BCrypt struct {
|
||||
cost int
|
||||
}
|
||||
|
||||
func NewBCrypt(cost int) *BCrypt {
|
||||
return &BCrypt{cost: cost}
|
||||
}
|
||||
|
||||
func (b *BCrypt) Algorithm() string {
|
||||
return "bcrypt"
|
||||
}
|
||||
|
||||
func (b *BCrypt) Hash(value []byte) ([]byte, error) {
|
||||
return bcrypt.GenerateFromPassword(value, b.cost)
|
||||
}
|
||||
|
||||
func (b *BCrypt) CompareHash(hashed, value []byte) error {
|
||||
return bcrypt.CompareHashAndPassword(hashed, value)
|
||||
}
|
Reference in New Issue
Block a user