aes

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2022 License: MIT Imports: 10 Imported by: 5

Documentation

Overview

reference:

https://blog.csdn.net/wade3015/article/details/84454836

reference:

https://gist.github.com/temoto/5052503

reference:

https://github.com/SimonWaldherr/golang-examples/blob/master/advanced/aesChacha20Poly1305.go

reference:

https://github.com/SimonWaldherr/golang-examples/blob/master/advanced/aesgcm.go

Index

Constants

This section is empty.

Variables

View Source
var SIZE = []int{128, 192, 256}

Functions

func GenerateIV

func GenerateIV(size int) (string, error)

func GenerateKey

func GenerateKey(size int) (string, error)

func GenerateNonce

func GenerateNonce(size int) (string, error)

func RandomString

func RandomString(length int) string

Types

type Aes

type Aes struct {
	Size     int
	Encoding Encoding
	IV       []byte
}

func New

func New(size int, encoding Encoding, iv []byte) (*Aes, error)

func (*Aes) BlockSize

func (a *Aes) BlockSize() int

func (*Aes) GenerateIV

func (a *Aes) GenerateIV() (string, error)

func (*Aes) GenerateKey

func (a *Aes) GenerateKey() (string, error)

func (*Aes) GenerateNonce

func (a *Aes) GenerateNonce() (string, error)

func (*Aes) GetIV

func (a *Aes) GetIV(key []byte) []byte

func (*Aes) GetNonce

func (a *Aes) GetNonce(key []byte) []byte

reference: https://qa.1r1g.cn/crypto/ask/4985151/

func (*Aes) Name

func (a *Aes) Name() string

type Base32Encoding

type Base32Encoding struct{}

func (*Base32Encoding) DecodeString

func (e *Base32Encoding) DecodeString(s string) ([]byte, error)

func (*Base32Encoding) EncodeToString

func (e *Base32Encoding) EncodeToString(src []byte) string

type Base64Encoding

type Base64Encoding struct{}

func (*Base64Encoding) DecodeString

func (e *Base64Encoding) DecodeString(s string) ([]byte, error)

func (*Base64Encoding) EncodeToString

func (e *Base64Encoding) EncodeToString(src []byte) string

type CBC

type CBC struct {
	Aes
	Padding Padding
}

func NewCBC

func NewCBC(size int, padding Padding, encoding Encoding, iv []byte) (*CBC, error)

func (*CBC) Decrypt

func (a *CBC) Decrypt(cipherbytes, key []byte) (plainbytes []byte, err error)

func (*CBC) DecryptString

func (a *CBC) DecryptString(ciphertext, secret string) (plaintext string, err error)

func (*CBC) Encrypt

func (a *CBC) Encrypt(plainbytes, key []byte) (cipherbytes []byte, err error)

func (*CBC) EncryptString

func (a *CBC) EncryptString(plaintext, secret string) (ciphertext string, err error)

type CFB

type CFB struct {
	Aes
}

func NewCFB

func NewCFB(size int, encoding Encoding, iv []byte) (*CFB, error)

func (*CFB) Decrypt

func (a *CFB) Decrypt(cipherbytes, key []byte) (plainbytes []byte, err error)

func (*CFB) DecryptString

func (a *CFB) DecryptString(ciphertext, secret string) (plaintext string, err error)

func (*CFB) Encrypt

func (a *CFB) Encrypt(plainbytes, key []byte) (cipherbytes []byte, err error)

func (*CFB) EncryptString

func (a *CFB) EncryptString(plaintext, secret string) (ciphertext string, err error)

type Chacha20Poly1305

type Chacha20Poly1305 struct {
	Aes
}

func NewChacha20Poly1305

func NewChacha20Poly1305(encoding Encoding, iv []byte) (*Chacha20Poly1305, error)

func (*Chacha20Poly1305) Decrypt

func (a *Chacha20Poly1305) Decrypt(cipherbytes, key []byte) (plainbytes []byte, err error)

func (*Chacha20Poly1305) DecryptString

func (a *Chacha20Poly1305) DecryptString(ciphertext, secret string) (plaintext string, err error)

func (*Chacha20Poly1305) Encrypt

func (a *Chacha20Poly1305) Encrypt(plainbytes, key []byte) (cipherbytes []byte, err error)

func (*Chacha20Poly1305) EncryptString

func (a *Chacha20Poly1305) EncryptString(plaintext, secret string) (ciphertext string, err error)

type Encoding

type Encoding interface {
	EncodeToString(src []byte) string
	DecodeString(s string) ([]byte, error)
}

type GCM

type GCM struct {
	Aes
}

func NewGCM

func NewGCM(size int, encoding Encoding, iv []byte) (*GCM, error)

func (*GCM) Decrypt

func (a *GCM) Decrypt(cipherbytes, key []byte) (plainbytes []byte, err error)

func (*GCM) DecryptString

func (a *GCM) DecryptString(ciphertext, secret string) (plaintext string, err error)

func (*GCM) Encrypt

func (a *GCM) Encrypt(plainbytes, key []byte) (cipherbytes []byte, err error)

func (*GCM) EncryptString

func (a *GCM) EncryptString(plaintext, secret string) (ciphertext string, err error)

type HexEncoding

type HexEncoding struct{}

func (*HexEncoding) DecodeString

func (e *HexEncoding) DecodeString(s string) ([]byte, error)

func (*HexEncoding) EncodeToString

func (e *HexEncoding) EncodeToString(src []byte) string

type PCKS7Padding

type PCKS7Padding struct{}

func (*PCKS7Padding) Padding

func (p *PCKS7Padding) Padding(plainbytes []byte, blockSize int) []byte

func (*PCKS7Padding) Unpadding

func (p *PCKS7Padding) Unpadding(plainbytes []byte, blockSize int) []byte

type Padding

type Padding interface {
	Padding(plainbytes []byte, blockSize int) []byte
	Unpadding(plainbytes []byte, blockSize int) []byte
}

type ZerosPadding

type ZerosPadding struct{}

func (*ZerosPadding) Padding

func (p *ZerosPadding) Padding(plainbytes []byte, blockSize int) []byte

func (*ZerosPadding) Unpadding

func (p *ZerosPadding) Unpadding(plainbytes []byte, blockSize int) []byte

Jump to

Keyboard shortcuts

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