tools

package
v0.0.0-...-a3ef211 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2023 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComputeHmacSha256

func ComputeHmacSha256(message string, secret string) string

func Encode

func Encode(rawPwd string, options *Options) (string, string)

Encode takes two arguments, a raw password, and a pointer to an Options struct. In order to use default options, pass `nil` as the second argument. It returns the generated salt and encoded key for the user.

func GetRemoteClientIp

func GetRemoteClientIp(r *http.Request) string

func GetWithHeader

func GetWithHeader(path string, m map[string]string, proxy string) ([]byte, error)

func ISO

func ISO(t time.Time) string

func Post

func Post(url string, params any) ([]byte, error)

func Rand4Num

func Rand4Num() string

func ToFloat64

func ToFloat64(str string) float64

func ToInt64

func ToInt64(str string) int64

func ToTimeString

func ToTimeString(mill int64) string

func Unq

func Unq(prefix string) string

func Verify

func Verify(rawPwd string, salt string, encodedPwd string, options *Options) bool

Verify takes four arguments, the raw password, its generated salt, the encoded password, and a pointer to the Options struct, and returns a boolean value determining whether the password is the correct one or not. Passing `nil` as the last argument resorts to default options.

func ZeroTime

func ZeroTime() int64

Types

type Options

type Options struct {
	SaltLen      int
	Iterations   int
	KeyLen       int
	HashFunction func() hash.Hash
}

Options is a struct for custom values of salt length, number of iterations, the encoded key's length, and the hash function being used. If set to `nil`, default options are used: &Options{ 64, 10000, 128, "sha512" } SaltLen:用户生成的长度,默认64 Iterations: PBKDF2函数中的迭代次数,默认10000 KeyLen:BKDF2函数中编码密钥的长度,默认128 HashFunction: 使用的哈希算法,默认sha512

Jump to

Keyboard shortcuts

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