cipher

package
v1.1.14 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: Apache-2.0 Imports: 13 Imported by: 1

Documentation

Index

Constants

View Source
const (
	RndSeed int64 = -3250455768463625913
)

Variables

View Source
var (
	// ErrNotSupportStream for stream encryption
	ErrNotSupportStream = errors.New("not support stream encryption mode")
)

Functions

func DecryptBytesFunc

func DecryptBytesFunc(algo Algorithm, mode Mode, key, iv []byte) (
	enc func(src []byte) (dst []byte, err error), err error)

func DecryptStreamFunc

func DecryptStreamFunc(algo Algorithm, mode Mode, key, iv []byte) (
	dec func(dst io.Writer, src io.Reader) (err error), err error)

func EncryptBytesFunc

func EncryptBytesFunc(algo Algorithm, mode Mode, key, iv []byte) (
	enc func(src []byte) (dst []byte, err error), err error)

func EncryptStreamFunc

func EncryptStreamFunc(algo Algorithm, mode Mode, key, iv []byte) (
	enc func(dst io.Writer, src io.Reader) (err error), err error)

func NewDecFunc

func NewDecFunc(algo Algorithm, mode Mode, key, iv []byte) func(r io.Reader) io.ReadCloser

func NewEncFunc

func NewEncFunc(algo Algorithm, mode Mode, key, iv []byte) func(w io.Writer) io.WriteCloser

func PKCS7Pad

func PKCS7Pad(data []byte, blockSize int) []byte

PKCS7Pad Apply PKCS#7 padding

func PKCS7Unpad

func PKCS7Unpad(data []byte) ([]byte, error)

PKCS7Unpad Remove PKCS#7 padding

Types

type Algorithm

type Algorithm uint8
const (
	AlgorithmUnknown Algorithm = iota
	AlgorithmDES
	Algorithm3DES
	AlgorithmAES
	AlgorithmRC4
	AlgorithmChaCha20poly1305
	AlgorithmXChaCha20poly1305
	AlgorithmSM4 // GM/T 0002-2012
)

func ParseAlgorithm

func ParseAlgorithm(s any) Algorithm

func (Algorithm) IsValid

func (e Algorithm) IsValid() bool

func (Algorithm) String

func (e Algorithm) String() string

func (Algorithm) Value

func (e Algorithm) Value() uint8

type Mode

type Mode uint8
const (
	ModeUnknown Mode = iota
	ModeECB
	ModeCBC
	ModeCFB
	ModeCTR
	ModeOFB
	ModeGCM
)

func ParseMode

func ParseMode(s any) Mode

func (Mode) IsValid

func (m Mode) IsValid() bool

func (Mode) NeedIV

func (m Mode) NeedIV() bool

func (Mode) ShouldPadding

func (m Mode) ShouldPadding() bool

func (Mode) String

func (m Mode) String() string

func (Mode) SupportStream

func (m Mode) SupportStream() bool

func (Mode) Value

func (m Mode) Value() uint8

Jump to

Keyboard shortcuts

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