signature

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// 签名公共字段:
	SignPublicKeyName  = "public_key"  // 字段名: 公钥
	SignPrivateKeyName = "private_key" // 字段名: 私钥
	SignNonceName      = "nonce"       // 字段名: 随机串
	SignTimestampName  = "ts"          // 字段名: 时间戳
	SignTypeName       = "sign_type"   // 字段名: 签名算法类型
	SignResultName     = "sign"        // 字段名: 签名结果

	// 签名算法类型:
	SignTypeMD5    = "md5"    // md5
	SignTypeSHA256 = "sha256" // sha256
	SignTypeSHA512 = "sha512" // sha512
)

Variables

This section is empty.

Functions

func SignSHA256

func SignSHA256(
	payload DictType,
	publicKey string,
	nonce string,
	timestamp string,
	toLower bool,
	keyFn PrivateKeyFunc,

) string

use default field name:

func VerifySHA256 added in v0.1.13

func VerifySHA256(
	data DictType,
	toLower bool,
	keyFn PrivateKeyFunc,
) bool

use default field name:

func WithMD5 added in v0.1.13

func WithMD5(data string, privateKey string) string

md5 签名:

func WithSHA256 added in v0.1.13

func WithSHA256(data string, privateKey string) string

sha256 签名:

func WithSHA512 added in v0.1.13

func WithSHA512(data string, privateKey string) string

sha512 签名:

Types

type DictType added in v0.1.14

type DictType interface {
	Encode() string
	Get(key string) interface{}
	Set(key string, value interface{})
	Del(key string)
}

interface:

type PrivateKeyFunc

type PrivateKeyFunc func(publicKey string) (key string, err error)

get appSecret/privateKey by appKey/publicKey

type SignAlgorithmFunc added in v0.1.11

type SignAlgorithmFunc func(data string, privateKey string) (digest string)

签名算法: useMD5/sha256/sha512

type Signer

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

func New

func New(publicKeyName string, nonceName string, timestampName string) *Signer

func (*Signer) Sign added in v0.1.11

func (m *Signer) Sign(
	payload DictType,
	publicKey string,
	nonce string,
	timestamp string,
	signType string,
	toLower bool,
	keyFn PrivateKeyFunc,
	signFn SignAlgorithmFunc,
) (sign string)

签名生成:

func (*Signer) SignMD5

func (m *Signer) SignMD5(
	payload DictType,
	publicKey string,
	nonce string,
	timestamp string,
	toLower bool,
	keyFn PrivateKeyFunc,
) string

func (*Signer) SignSHA256 added in v0.1.11

func (m *Signer) SignSHA256(
	payload DictType,
	publicKey string,
	nonce string,
	timestamp string,
	toLower bool,
	keyFn PrivateKeyFunc,
) string

sign with SHA256:

func (*Signer) SignSHA512 added in v0.1.11

func (m *Signer) SignSHA512(payload DictType,
	publicKey string,
	nonce string,
	timestamp string,
	toLower bool,
	keyFn PrivateKeyFunc,
) string

sign with SHA512:

func (*Signer) Verify added in v0.1.11

func (m *Signer) Verify(
	data DictType,
	signType string,
	toLower bool,
	keyFn PrivateKeyFunc,
	signFn SignAlgorithmFunc,
) bool

签名验证:

func (*Signer) VerifyMD5

func (m *Signer) VerifyMD5(
	data DictType,
	toLower bool,
	keyFn PrivateKeyFunc,
) bool

func (*Signer) VerifySHA256 added in v0.1.11

func (m *Signer) VerifySHA256(
	data DictType,
	toLower bool,
	keyFn PrivateKeyFunc,
) bool

func (*Signer) VerifySHA512 added in v0.1.11

func (m *Signer) VerifySHA512(
	data DictType,
	toLower bool,
	keyFn PrivateKeyFunc,
) bool

Jump to

Keyboard shortcuts

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