cipher

package
v1.1.7 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2018 License: MIT Imports: 17 Imported by: 1

Documentation

Index

Constants

View Source
const (
	OK                     ErrorCodeType = 0
	ValidateSignatureError               = -40001
	ParseXMLError                        = -40002
	ComputeSignatureError                = -40003
	IllegalAesKey                        = -40004
	ValidateAppidError                   = -40005
	EncryptAESError                      = -40006
	DecryptAESError                      = -40007
	IllegalBuffer                        = -40008
	EncodeBase64Error                    = -40009
	DecodeBase64Error                    = -40010
	GenReturnXMLError                    = -40011
)

error code types

Variables

View Source
var (
	ErrorKeyMustBePEMEncoded = errors.New("key must be pem encoded")
	ErrorNotECPublicKey      = errors.New("key is not a valid ECDSA public key")
	ErrorNotECPrivateKey     = errors.New("key is not a valid ECDSA private key")
	ErrorNotRSAPrivateKey    = errors.New("key is not a valid RSA private key")
	ErrorNotRSAPublicKey     = errors.New("key is not a valid RSA public key")
)

all defined errors

View Source
var ErrorCode = map[string]ErrorCodeType{
	"OK":                     OK,
	"ValidateSignatureError": ValidateSignatureError,
	"ParseXMLError":          ParseXMLError,
	"ComputeSignatureError":  ComputeSignatureError,
	"IllegalAesKey":          IllegalAesKey,
	"ValidateAppidError":     ValidateAppidError,
	"EncryptAESError":        EncryptAESError,
	"DecryptAESError":        DecryptAESError,
	"IllegalBuffer":          IllegalBuffer,
	"EncodeBase64Error":      EncodeBase64Error,
	"DecodeBase64Error":      DecodeBase64Error,
	"GenReturnXMLError":      GenReturnXMLError,
}

ErrorCode ErrorCode

Functions

func Base64Decode

func Base64Decode(b []byte) ([]byte, error)

Base64Decode Base64Decode

func Base64Encode

func Base64Encode(b []byte) []byte

Base64Encode Base64Encode

func NewECBDecrypter added in v1.1.7

func NewECBDecrypter(b cipher.Block) cipher.BlockMode

NewECBDecrypter returns a BlockMode which decrypts in electronic code book mode, using the given Block.

func NewECBEncrypter added in v1.1.7

func NewECBEncrypter(b cipher.Block) cipher.BlockMode

NewECBEncrypter returns a BlockMode which encrypts in electronic code book mode, using the given Block.

func PKCS7Padding

func PKCS7Padding(ciphertext []byte, blockSize int) []byte

PKCS7Padding PKCS7Padding

func PKCS7UnPadding

func PKCS7UnPadding(plantText []byte) []byte

PKCS7UnPadding PKCS7UnPadding

func ParseRSAPrivateKeyFromPEM

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

ParseRSAPrivateKeyFromPEM Parse PEM encoded PKCS1 or PKCS8 private key

func ParseRSAPublicKeyFromPEM

func ParseRSAPublicKeyFromPEM(key []byte) (*rsa.PublicKey, error)

ParseRSAPublicKeyFromPEM Parse PEM encoded PKCS1 or PKCS8 public key

func RSADecrypt

func RSADecrypt(pri string, text string) string

RSADecrypt RSADecrypt

func RSAEncrypt

func RSAEncrypt(pub string, text string) string

RSAEncrypt RSAEncrypt

func SHA1

func SHA1(text ...string) string

SHA1 SHA1

func ZeroPadding added in v1.1.7

func ZeroPadding(ciphertext []byte, blockSize int) []byte

func ZeroUnPadding added in v1.1.7

func ZeroUnPadding(origData []byte) []byte

Types

type BizMsg

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

BizMsg BizMsg

func NewBizMsg

func NewBizMsg(token, key, id string) *BizMsg

NewBizMsg NewBizMsg

func (*BizMsg) Decrypt

func (m *BizMsg) Decrypt(text string, msgSignature, timeStamp, nonce string) ([]byte, error)

Decrypt ...

func (*BizMsg) Encrypt

func (m *BizMsg) Encrypt(text, timeStamp, nonce string) (string, error)

Encrypt ...

type Cipher

type Cipher interface {
	Type() CryptType
	SetParameter(key string, val []byte)
	GetParameter(key string) []byte
	Encrypt([]byte) ([]byte, error)
	Decrypt(data []byte) ([]byte, error)
}

Cipher ...

func CryptAES128CBC

func CryptAES128CBC() Cipher

CryptAES128CBC ...

func CryptAES256ECB added in v1.1.7

func CryptAES256ECB() Cipher

func CryptRSA

func CryptRSA() Cipher

CryptRSA ...

func New

func New(cryptType CryptType) Cipher

New create a new cipher

type CryptType

type CryptType int

CryptType ...

const (
	AES128CBC CryptType = iota
	RSA                 = iota
)

AES128CBC ...

type DataCrypt

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

DataCrypt DataCrypt

func NewDataCrypt

func NewDataCrypt(id string) *DataCrypt

NewDataCrypt NewDataCrypt

func (*DataCrypt) Decrypt

func (c *DataCrypt) Decrypt(data, iv, key string) ([]byte, error)

Decrypt ... Deprecated: change to cipher

type ErrorCodeType

type ErrorCodeType int

ErrorCodeType ErrorCodeType

type InstanceFunc

type InstanceFunc func() Cipher

InstanceFunc ...

type PrpCrypt

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

PrpCrypt PrpCrypt

func NewPrp

func NewPrp(key []byte) *PrpCrypt

NewPrp NewPrp

func (*PrpCrypt) BytesLength

func (c *PrpCrypt) BytesLength(b []byte) uint32

BytesLength BytesLength

func (*PrpCrypt) Decrypt

func (c *PrpCrypt) Decrypt(ciphertext []byte, appid string) ([]byte, error)

Decrypt ...

func (*PrpCrypt) Encrypt

func (c *PrpCrypt) Encrypt(text string, appid string) ([]byte, error)

Encrypt ...

func (*PrpCrypt) LengthBytes

func (c *PrpCrypt) LengthBytes(s string) []byte

LengthBytes LengthBytes

func (*PrpCrypt) Random

func (c *PrpCrypt) Random() string

Random Random

Jump to

Keyboard shortcuts

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