secret

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2020 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrBase64DecodeError    = "签名base64解码异常"
	ErrSignatureCheckError  = "签名校验失败"
	ErrSignatureCreateError = "签名创建失败"
	ErrSigningMethodError   = "错误的签名方法"
)
View Source
const (
	SigningMethodRSA256 = "SHA256"
	SigningMethodRSA512 = "SHA512"
	SigningMethodRSA384 = "SHA384"
)

Variables

View Source
var (
	ErrKeyMustBePEMEncoded = errors.New("invalid key: Key must be PEM encoded")
	ErrNotRSAPrivateKey    = errors.New("key is not a valid RSA private key")
	ErrNotRSAPublicKey     = errors.New("key is not a valid RSA public key")
)
View Source
var (
	// ErrNotECDSAPrivateKey = errors.New("key is not a valid ECDSA private key")
	ErrNotECDSAPublicKey = errors.New("key is not a valid ECDSA public key")
)

Functions

func AESDecrypt

func AESDecrypt(encrypted string, key []byte) ([]byte, error)

func AESEncrypt

func AESEncrypt(origin []byte, key []byte) (string, error)

AESEncrypt AES CBC加密 key 长度必须为 16, 24 或 32

func ECDSASign

func ECDSASign(data []byte, method string, privateKey *ecdsa.PrivateKey) (string, error)

ECDSASign ecdsa签名

func ECDSAVerify

func ECDSAVerify(content []byte, signature string, method string, publicKey *ecdsa.PublicKey) error

ECDSAVerify ecdsa 验证签名

func HMACSHA256

func HMACSHA256(data, key []byte) string

HMACSHA256 hmac 签名

func HMACSHA512

func HMACSHA512(data, key []byte) string

HMACSHA512 hmac 验签

func PKCS7Padding

func PKCS7Padding(text []byte, size int) []byte

补码

func PKCS7UnPadding

func PKCS7UnPadding(origData []byte) []byte

去补码

func ParseECDSAPrivate

func ParseECDSAPrivate(data []byte) (*ecdsa.PrivateKey, error)

func ParseECDSAPublic

func ParseECDSAPublic(data []byte) (*ecdsa.PublicKey, error)

func ParseRSAPrivateKey

func ParseRSAPrivateKey(key []byte) (*rsa.PrivateKey, error)

func ParseRSAPublicKey

func ParseRSAPublicKey(data []byte) (*rsa.PublicKey, error)

func RSADecrypt

func RSADecrypt(encrypted string, privateKey *rsa.PrivateKey) ([]byte, error)

解密

func RSAEncrypt

func RSAEncrypt(origData []byte, publicKey *rsa.PublicKey) (string, error)
RSA加密

待加密字段长度不能大于 117 (128-11)

func RSASign

func RSASign(data []byte, method string, privateKey *rsa.PrivateKey) (string, error)

RSASign 使用 RSA 签名

func RSAVerify

func RSAVerify(content []byte, signature string, method string, publicKey *rsa.PublicKey) error

RSAVerify rsa验证签名

Types

type ECDSAKey

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

func CreateECDSAKey

func CreateECDSAKey() (*ECDSAKey, error)

func CreateECDSAKeyByPrivateKey

func CreateECDSAKeyByPrivateKey(key *ecdsa.PrivateKey) *ECDSAKey

func (*ECDSAKey) EncodePrivateToPEM

func (ek *ECDSAKey) EncodePrivateToPEM() ([]byte, error)

func (*ECDSAKey) EncodePublicToPem

func (ek *ECDSAKey) EncodePublicToPem() ([]byte, error)

func (*ECDSAKey) PrivateKey

func (ek *ECDSAKey) PrivateKey() *ecdsa.PrivateKey

func (*ECDSAKey) PublicKey

func (ek *ECDSAKey) PublicKey() *ecdsa.PublicKey

type RSAKey

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

func CreateRSAKey

func CreateRSAKey(size int) (*RSAKey, error)

func CreateRSAKeyByPrivateKey

func CreateRSAKeyByPrivateKey(privateKey *rsa.PrivateKey) *RSAKey

func (*RSAKey) EncodePrivateToPEM

func (r *RSAKey) EncodePrivateToPEM() ([]byte, error)

func (*RSAKey) EncodePublicToPEM

func (r *RSAKey) EncodePublicToPEM() ([]byte, error)

func (*RSAKey) PrivateKey

func (r *RSAKey) PrivateKey() *rsa.PrivateKey

func (*RSAKey) PublicKey

func (r *RSAKey) PublicKey() *rsa.PublicKey

func (*RSAKey) Size

func (r *RSAKey) Size() int

Jump to

Keyboard shortcuts

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