aes

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decrypt

func Decrypt(msg, key []byte, opts ...Option) ([]byte, error)

Decrypt AES

support 128/192/256bit Mapping key length 16byte/24byte/32byte

support ECB/CBC/CTR/OFB/CFB mode

support Pkcs7/Pkcs5/Iso97971/AnsiX923/Zero/Empty/No padding

without iv default: mode = ECB/Pkcs7padding

withiv default: mode = CBC/Pkcs7padding

func Encrypt

func Encrypt(msg, key []byte, opts ...Option) ([]byte, error)

Encrypt AES

support 128/192/256bit Mapping key length 16byte/24byte/32byte

support ECB/CBC/CTR/OFB/CFB mode

support Pkcs7/Pkcs5/Iso97971/AnsiX923/Zero/Empty/No padding

without iv default: mode = ECB/Pkcs7padding

withiv default: mode = CBC/Pkcs7padding

Types

type Cipher

type Cipher struct {
	Error error
	// contains filtered or unexported fields
}

func New

func New(key []byte, opts ...Option) *Cipher

New AES

support 128/192/256bit Mapping key length 16byte/24byte/32byte

support ECB/CBC/CTR/OFB/CFB mode

support Pkcs7/Pkcs5/Iso97971/AnsiX923/Zero/Empty/No padding

without iv default: mode = ECB/Pkcs7padding

withiv default: mode = CBC/Pkcs7padding

New([]byte("1234567890123456")).Encrypt(msg).String(gcrypto.Base64)
New([]byte("1234567890123456")).Decrypt(msg).String(gcrypto.Raw)
New([]byte("1234567890123456")).Decrypt(msg).Bytes()
New([]byte("1234567890123456")).Decrypt(msg).Error
New([]byte("1234567890123456")).Release() // free Cipher global aespool

func (*Cipher) Bytes

func (s *Cipher) Bytes() []byte

func (*Cipher) Decrypt

func (s *Cipher) Decrypt(src []byte) *Cipher

Decrypt decrypts with given mode and padding.

func (*Cipher) Encrypt

func (s *Cipher) Encrypt(src []byte) *Cipher

Encrypt encrypts with given mode and padding

func (*Cipher) String

func (s *Cipher) String(enc func([]byte) string) (ss string)

type Mode

type Mode uint8
const (
	CBC Mode = iota
	CFB
	CTR
	OFB
	ECB
)

type Option

type Option func(*opt)

func WithIV

func WithIV(iv []byte) Option

func WithMode

func WithMode(mode Mode) Option

func WithPadding

func WithPadding(padding Padding) Option

type Padding

type Padding uint8
const (
	Pkcs7 Padding = iota
	Pkcs5
	Iso97971
	AnsiX923
	Zero
	Empty
	No
)

Jump to

Keyboard shortcuts

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