Documentation ¶
Index ¶
Constants ¶
View Source
const ( // ROUNDS is the iteration counts. ROUNDS = 4096 // KEY_LENGTH is how many bytes to generate as output. KEY_LENGTH = 32 // DEFAULT_HASHFUNCTION is for calculating HMAC. Defaulting to sha256. DEFAULT_HASHFUNCTION = SHA256 // SALT_LENGTH is the default salth length in bytes. SALT_LENGTH = 16 )
Variables ¶
View Source
var ErrEmptyField error = errors.New("function parameters must not be empty")
View Source
var ErrInvalidHashFunction error = errors.New("invalid hash function was provided")
Functions ¶
func Hash ¶
Hash creates a PHC-formatted hash with config provided
import ( "fmt" "github.com/aldy505/phc-crypto/pbkdf2" ) func main() { hash, err := pbkdf2.Hash("password", pbkdf2.Config{ HashFunc: pbkdf2.SHA512, }) if err != nil { fmt.Println(err) } fmt.Println(hash) // $pbkdf2sha512$v=0$i=4096$87a39b3cf30626bc7cf6534ac3a14ddf$d32093416bf521ff0... }
func Verify ¶
Verify checks the hash if it's equal (by an algorithm) to plain text provided.
import ( "fmt" "github.com/aldy505/phc-crypto/pbkdf2" ) func main() { hash := "$pbkdf2sha512$v=0$i=4096$87a39b3cf30626bc7cf6534ac3a14ddf$d32093416bf521ff0..." verify, err := pbkdf2.Verify(hash, "password") if err != nil { fmt.Println(err) } fmt.Println(verify) // true }
Types ¶
type Config ¶
type Config struct { Rounds int KeyLen int HashFunc HashFunction SaltLen int }
Config initialize the config require to create a hash function
type HashFunction ¶ added in v1.2.0
type HashFunction int
const ( SHA1 HashFunction = iota SHA256 SHA224 SHA512 SHA384 MD5 )
Click to show internal directories.
Click to hide internal directories.