hashutil

package
v0.0.0-...-1cb0a1a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 9, 2024 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

package hashutil contains helper functions for generating and verifying hashes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateHash

func GenerateHash(password, salt string) string

GenerateHash returns a base64 encoded SHA-256 hash of the salted password.

func GenerateNonce

func GenerateNonce() string

GenerateNonce returns a random 16-byte nonce for the salt.

func IsValid

func IsValid(password, salt, hash string) bool

IsValid returns true if the hash matches the salted password.

func Sign

func Sign(key string, hashFunc HashFunc, header, payload string) []byte

Sign computes the HMAC using the given HashFunc type and returns the JWS signature.

Types

type HashFunc

type HashFunc func() hash.Hash

HashFunc is a factory function abstraction that returns a hash.Hash.

var HS256 HashFunc = func() hash.Hash { return sha256.New() }
var HS512 HashFunc = func() hash.Hash { return sha512.New() }

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL