codec

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2021 License: Apache-2.0 Imports: 19 Imported by: 26

README

codec

加密解密库

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDataToLarge      = errors.New("message too long for RSA public key size")
	ErrDataLen          = errors.New("data length error")
	ErrDataBroken       = errors.New("data broken, first byte is not zero")
	ErrKeyPairDismatch  = errors.New("data is not encrypted by the private key")
	ErrDecryption       = errors.New("decryption error")
	ErrPublicKey        = errors.New("get public key error")
	ErrPrivateKey       = errors.New("get private key error")
	ErrPublicKeyNotSet  = errors.New(`Please set the public key in advance`)
	ErrPrivateKeyNotSet = errors.New(`Please set the private key in advance`)
)
View Source
var AESKeyTypes = map[string]int{
	`AES-128`: aes128KeyLen,
	`AES-192`: aes192KeyLen,
	`AES-256`: aes256KeyLen,
}

AESKeyTypes AES Key类型

Functions

func AesGenKey

func AesGenKey(key []byte, typ ...string) []byte

func DesGenKey

func DesGenKey(key []byte) []byte

func NewECBDecrypter

func NewECBDecrypter(b cipher.Block) cipher.BlockMode

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

func NewECBEncrypter

func NewECBEncrypter(b cipher.Block) cipher.BlockMode

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

func PKCS5Padding

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

func PKCS5UnPadding

func PKCS5UnPadding(origData []byte) []byte

func PKCS7Padding

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

func PKCS7UnPadding

func PKCS7UnPadding(origData []byte) []byte

func ZeroPadding

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

func ZeroUnPadding

func ZeroUnPadding(origData []byte) []byte

Types

type AesCBCCrypto

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

func NewAesCBCCrypto

func NewAesCBCCrypto(keyTypes ...string) *AesCBCCrypto

func (*AesCBCCrypto) Decode

func (c *AesCBCCrypto) Decode(cryptedData, authKey string) string

func (*AesCBCCrypto) DecodeBytes

func (c *AesCBCCrypto) DecodeBytes(cryptedData, authKey []byte) []byte

func (*AesCBCCrypto) Encode

func (c *AesCBCCrypto) Encode(rawData, authKey string) string

func (*AesCBCCrypto) EncodeBytes

func (c *AesCBCCrypto) EncodeBytes(rawData, authKey []byte) []byte

type AesCrypto

type AesCrypto struct {
	Codec
}

func NewAesCrypto

func NewAesCrypto(keyTypes ...string) *AesCrypto

type AesECBCrypto

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

func NewAesECBCrypto

func NewAesECBCrypto(keyTypes ...string) *AesECBCrypto

func (*AesECBCrypto) Decode

func (c *AesECBCrypto) Decode(cryptedData, authKey string) string

func (*AesECBCrypto) DecodeBytes

func (c *AesECBCrypto) DecodeBytes(cryptedData, authKey []byte) []byte

func (*AesECBCrypto) Encode

func (c *AesECBCrypto) Encode(rawData, authKey string) string

func (*AesECBCrypto) EncodeBytes

func (c *AesECBCrypto) EncodeBytes(rawData, authKey []byte) []byte

type Codec

type Codec interface {
	Encode(rawData, authKey string) string
	Decode(cryptedData, authKey string) string
	EncodeBytes(rawData, authKey []byte) []byte
	DecodeBytes(cryptedData, authKey []byte) []byte
}
var Default Codec = NewAesCrypto()

type DesCBCCrypto

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

func NewDesCBCCrypto

func NewDesCBCCrypto() *DesCBCCrypto

func (*DesCBCCrypto) Decode

func (d *DesCBCCrypto) Decode(cryptedStr, secret string) string

Decode DES CBC解密

func (*DesCBCCrypto) DecodeBytes

func (d *DesCBCCrypto) DecodeBytes(crypted, secret []byte) []byte

func (*DesCBCCrypto) Encode

func (d *DesCBCCrypto) Encode(text, secret string) string

Encode DES CBC加密

func (*DesCBCCrypto) EncodeBytes

func (d *DesCBCCrypto) EncodeBytes(text, secret []byte) []byte

func (*DesCBCCrypto) GenKey

func (d *DesCBCCrypto) GenKey(key []byte) []byte

type DesECBCrypto

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

func NewDesECBCrypto

func NewDesECBCrypto() *DesECBCrypto

func (*DesECBCrypto) Decode

func (d *DesECBCrypto) Decode(crypted, secret string) string

func (*DesECBCrypto) DecodeBytes

func (d *DesECBCrypto) DecodeBytes(crypted, secret []byte) []byte

func (*DesECBCrypto) Encode

func (d *DesECBCrypto) Encode(text, secret string) string

func (*DesECBCrypto) EncodeBytes

func (d *DesECBCrypto) EncodeBytes(text, secret []byte) []byte

func (*DesECBCrypto) GenKey

func (d *DesECBCrypto) GenKey(key []byte) []byte

type RSA added in v0.0.2

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

func NewRSA added in v0.0.2

func NewRSA() *RSA

func (*RSA) PrivateKey added in v0.0.2

func (r *RSA) PrivateKey() *RSAPrivateKey

func (*RSA) PublicKey added in v0.0.2

func (r *RSA) PublicKey() *RSAPublicKey

func (*RSA) SetPrivateKey added in v0.0.2

func (r *RSA) SetPrivateKey(privKey string) (err error)

func (*RSA) SetPublicKey added in v0.0.2

func (r *RSA) SetPublicKey(pubKey string) (err error)

type RSAPrivateKey added in v0.0.2

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

func NewRSAPrivateKey added in v0.0.2

func NewRSAPrivateKey(priStr string) (r *RSAPrivateKey, err error)

设置私钥

func (*RSAPrivateKey) Decrypt added in v0.0.2

func (r *RSAPrivateKey) Decrypt(input []byte) ([]byte, error)

私钥解密

func (*RSAPrivateKey) Encrypt added in v0.0.2

func (rsas *RSAPrivateKey) Encrypt(input []byte) ([]byte, error)

私钥加密

func (*RSAPrivateKey) GetPrivatekey added in v0.0.2

func (r *RSAPrivateKey) GetPrivatekey() (*rsa.PrivateKey, error)

*rsa.PublicKey

func (*RSAPrivateKey) SignMd5 added in v0.0.3

func (r *RSAPrivateKey) SignMd5(data []byte) ([]byte, error)

*

  • 使用RSAWithMD5算法签名

func (*RSAPrivateKey) SignSha1 added in v0.0.3

func (r *RSAPrivateKey) SignSha1(data []byte) ([]byte, error)

*

  • 使用RSAWithSHA1算法签名

func (*RSAPrivateKey) SignSha256 added in v0.0.3

func (r *RSAPrivateKey) SignSha256(data []byte) ([]byte, error)

*

  • 使用RSAWithSHA256算法签名

type RSAPublicKey added in v0.0.2

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

func NewRSAPublicKey added in v0.0.2

func NewRSAPublicKey(pubStr string) (r *RSAPublicKey, err error)

设置公钥

func (*RSAPublicKey) Decrypt added in v0.0.2

func (r *RSAPublicKey) Decrypt(input []byte) ([]byte, error)

公钥解密

func (*RSAPublicKey) Encrypt added in v0.0.2

func (r *RSAPublicKey) Encrypt(input []byte) ([]byte, error)

公钥加密

func (*RSAPublicKey) GetPublickey added in v0.0.2

func (r *RSAPublicKey) GetPublickey() (*rsa.PublicKey, error)

*rsa.PrivateKey

func (*RSAPublicKey) VerifySignMd5 added in v0.0.3

func (r *RSAPublicKey) VerifySignMd5(data string, signData string) error

*

  • 使用RSAWithMD5验证签名

func (*RSAPublicKey) VerifySignSha1 added in v0.0.3

func (r *RSAPublicKey) VerifySignSha1(data []byte, sign []byte) error

*

  • 使用RSAWithSHA1验证签名

func (*RSAPublicKey) VerifySignSha256 added in v0.0.3

func (r *RSAPublicKey) VerifySignSha256(data []byte, sign []byte) error

*

  • 使用RSAWithSHA256验证签名

Jump to

Keyboard shortcuts

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