codec

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidPriKey indicates the invalid private key.
	ErrInvalidPriKey = errors.New("invalid private key")
	// ErrInvalidPubKey indicates the invalid public key.
	ErrInvalidPubKey = errors.New("invalid public key")
	// ErrPubKeyOutOfBound indicates the public key is out of bound.
	ErrPubKeyOutOfBound = errors.New("public key out of bound")
)
View Source
var (
	// ErrPrivateKey indicates the invalid private key.
	ErrPrivateKey = errors.New("private key error")
	// ErrPublicKey indicates the invalid public key.
	ErrPublicKey = errors.New("failed to parse PEM block containing the public key")
	// ErrNotRsaKey indicates the invalid RSA key.
	ErrNotRsaKey = errors.New("key type is not RSA")
)
View Source
var ErrPaddingSize = errors.New("padding size error")

ErrPaddingSize indicates bad padding size.

Functions

func ComputeKey

func ComputeKey(pubKey, priKey *big.Int) (*big.Int, error)

ComputeKey returns a key from public key and private key.

func EcbDecrypt

func EcbDecrypt(key, src []byte) ([]byte, error)

EcbDecrypt decrypts src with the given key.

func EcbDecryptBase64

func EcbDecryptBase64(key, src string) (string, error)

EcbDecryptBase64 decrypts base64 encoded src with the given base64 encoded key. The returned string is also base64 encoded.

func EcbEncrypt

func EcbEncrypt(key, src []byte) ([]byte, error)

EcbEncrypt encrypts src with the given key.

func EcbEncryptBase64

func EcbEncryptBase64(key, src string) (string, error)

EcbEncryptBase64 encrypts base64 encoded src with the given base64 encoded key. The returned string is also base64 encoded.

func Gunzip

func Gunzip(bs []byte) ([]byte, error)

Gunzip uncompresses bs.

func Gzip

func Gzip(bs []byte) []byte

Gzip compresses bs.

func Hmac

func Hmac(key []byte, body string) []byte

Hmac returns HMAC bytes for body with the given key.

func HmacBase64

func HmacBase64(key []byte, body string) string

HmacBase64 returns the base64 encoded string of HMAC for body with the given key.

func NewECBDecrypter

func NewECBDecrypter(b cipher.Block) cipher.BlockMode

NewECBDecrypter returns an ECB decrypter.

func NewECBEncrypter

func NewECBEncrypter(b cipher.Block) cipher.BlockMode

NewECBEncrypter returns an ECB encrypter.

func NewPublicKey

func NewPublicKey(bs []byte) *big.Int

NewPublicKey returns a public key from the given bytes.

Types

type DhKey

type DhKey struct {
	PriKey *big.Int
	PubKey *big.Int
}

DhKey defines the Diffie Hellman key.

func GenerateKey

func GenerateKey() (*DhKey, error)

GenerateKey returns a Diffie Hellman key.

func (*DhKey) Bytes

func (k *DhKey) Bytes() []byte

Bytes returns public key bytes.

type RsaDecrypter

type RsaDecrypter interface {
	Decrypt(input []byte) ([]byte, error)
	DecryptBase64(input string) ([]byte, error)
}

RsaDecrypter represents a RSA decrypter.

func NewRsaDecrypter

func NewRsaDecrypter(file string) (RsaDecrypter, error)

NewRsaDecrypter returns a RsaDecrypter with the given file.

type RsaEncrypter

type RsaEncrypter interface {
	Encrypt(input []byte) ([]byte, error)
}

RsaEncrypter represents a RSA encrypter.

func NewRsaEncrypter

func NewRsaEncrypter(key []byte) (RsaEncrypter, error)

NewRsaEncrypter returns a RsaEncrypter with the given key.

Jump to

Keyboard shortcuts

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