secret

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 3, 2023 License: BSD-1-Clause Imports: 17 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Day0Hasher = Hasher{hash0SHA256, compare0SHA256} // Sunday     (SHA256)
	Day1Hasher = Hasher{hash1MD5, compare1MD5}       // Monday     (MD5)
	Day2Hasher = Hasher{hash2SHA512, compare2SHA512} // Tuesday    (SHA512)
	Day3Hasher = Hasher{hash3SHA384, compare3SHA384} // Wednesday  (SHA384)
	Day4Hasher = Hasher{hash4Bcrypt, compare4Bcrypt} // Thursday   (Bcrypt)
	Day5Hasher = Hasher{hash5ARGON2, compare5ARGON2} // Friday     (ARGON2)
	Day6Hasher = Hasher{hash6PBKDF2, compare6PBKDF2} // Saturday   (PBKDF2)
)

Functions

func Compare

func Compare(data, salt []byte, hash string) bool

Compares the data with the salt and the hash. If the hash is not in the correct format, it will return false.

func Hash

func Hash(data, salt []byte) string

Hashes the data with the salt, if the algorithm for that day supports it. If not, hash the data, appending the salt to it.

func HashForDay

func HashForDay(data, salt []byte, day time.Weekday) string

Recommended use is only in testing!

Types

type CompareFunc

type CompareFunc func(data, salt []byte, hash string) bool

A compare function should return true if the data and salt match the hash.

type HashFunc

type HashFunc func(data, salt []byte) string

A hash function should return a hash of the data and salt.

type HashUint

type HashUint uint32

func FnvHash

func FnvHash(s string) HashUint

Hashes any string to a 32-bit integer

func (HashUint) Compare

func (h HashUint) Compare(other HashUint) bool

func (HashUint) String

func (h HashUint) String() string

type Hasher

type Hasher struct {
	// contains filtered or unexported fields
}

A hasher is a struct that contains a hash function and a compare function.

The hash function should return a hash of the data and salt.

The compare function should return true if the data and salt match the hash.

type Key

type Key interface {
	// Get the bytes crypto interface.
	Bytes() *_byteCrypto
	// Get the html safe crypto interface.
	HTMLSafe() *_htmlSafe
	// Get a new aes key from the secret key.
	KeyFromSecret() *[32]byte
	// Generate a sha256 hash from the secret key.
	Sha256() string
	// Verify a sha256 hash with the secret key.
	VerifySha256(hash string) bool
	// Sign a string with the secret key.
	Sign(data string) string
	// Verify a string with the secret key.
	Verify(data, signature string) bool
	// Raw returns the raw secret key.
	Raw() string
}
var KEY Key = New("THIS-IS-NOT-SAFE-FOR-PRODUCTION-" + strconv.FormatInt(time.Now().Unix(), 10))

func New

func New(key string) Key

Create a new secret key.

Jump to

Keyboard shortcuts

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