Help us shape the future of Go! Take the 2026 Go Developer Survey

codec

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2026 License: MIT Imports: 15 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 deprecated

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

Deprecated: EcbDecrypt decrypts src with the given key. ECB mode is insecure for multi-block data. Use AES-GCM instead.

func EcbDecryptBase64 deprecated

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

Deprecated: EcbDecryptBase64 decrypts base64 encoded src with the given base64 encoded key. The returned string is also base64 encoded. ECB mode is insecure for multi-block data. Use AES-GCM instead.

func EcbEncrypt deprecated

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

Deprecated: EcbEncrypt encrypts src with the given key. ECB mode is insecure for multi-block data. Use AES-GCM instead.

func EcbEncryptBase64 deprecated

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

Deprecated: EcbEncryptBase64 encrypts base64 encoded src with the given base64 encoded key. The returned string is also base64 encoded. ECB mode is insecure for multi-block data. Use AES-GCM instead.

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 deprecated

func NewECBDecrypter(b cipher.Block) cipher.BlockMode

Deprecated: NewECBDecrypter returns an ECB decrypter. ECB mode is insecure for multi-block data. Use AES-GCM instead.

func NewECBEncrypter deprecated

func NewECBEncrypter(b cipher.Block) cipher.BlockMode

Deprecated: NewECBEncrypter returns an ECB encrypter. ECB mode is insecure for multi-block data. Use AES-GCM instead.

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 deprecated

func NewRsaDecrypter(file string) (RsaDecrypter, error)

Deprecated: NewRsaDecrypter returns a RsaDecrypter with the given file. PKCS#1 v1.5 padding is vulnerable to padding oracle attacks. Use NewRsaOAEPDecrypter instead.

func NewRsaOAEPDecrypter

func NewRsaOAEPDecrypter(file string) (RsaDecrypter, error)

NewRsaOAEPDecrypter returns a RsaDecrypter using OAEP with SHA-256.

type RsaEncrypter

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

RsaEncrypter represents a RSA encrypter.

func NewRsaEncrypter deprecated

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

Deprecated: NewRsaEncrypter returns a RsaEncrypter with the given key. PKCS#1 v1.5 padding is vulnerable to padding oracle attacks. Use NewRsaOAEPEncrypter instead.

func NewRsaOAEPEncrypter

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

NewRsaOAEPEncrypter returns a RsaEncrypter using OAEP with SHA-256.

Jump to

Keyboard shortcuts

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