signature

package
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: May 13, 2023 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckToken

func CheckToken(tokenStr string, pub *rsa.PublicKey, token interface{}) error

CheckToken 验证Token签名是否正确,如果正确则使用Json反序列化为传入结构

func EncodeAndSignToken

func EncodeAndSignToken(token interface{}, priv *rsa.PrivateKey) (string, error)

EncodeAndSignToken 编码和签名Token

func GenerateKeyPairs

func GenerateKeyPairs(keyName string, bits int) (privKey *rsa.PrivateKey, err error)

GenerateKeyPairs 生成指定名字的指定bit位数公私钥对

func ReadPrivKey

func ReadPrivKey(keyName string) (*rsa.PrivateKey, error)

ReadPrivKey 读取文件中的私钥

func ReadPubKey

func ReadPubKey(keyName string) (*rsa.PublicKey, error)

ReadPubKey 读取文件中的公钥

func Sign

func Sign(data []byte, priv *rsa.PrivateKey) ([]byte, error)

Sign 使用指定私钥对数据进行签名 用 SHA-256 算法对数据进行摘要

func Verify

func Verify(data, sig []byte, pub *rsa.PublicKey) (bool, error)

Verify 使用公钥对数据进行验签 用 SHA-256 算法对数据进行摘要

Types

type Key

type Key struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Key 签名秘钥,可能只有公钥,也可能包含私钥

func GetKey

func GetKey(keyName string) *Key

GetKey 获取一个指定名字的Key

func (*Key) Name

func (key *Key) Name() string

Name 秘钥的名字

func (*Key) Priv

func (key *Key) Priv() (*rsa.PrivateKey, error)

Priv 获取私钥

func (*Key) Pub

func (key *Key) Pub() (*rsa.PublicKey, error)

Pub 获取公钥

Jump to

Keyboard shortcuts

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