vcipher

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2021 License: MIT Imports: 4 Imported by: 0

README

vcipher

AES256-CBC

a, _ := vAES.AES_256(key.NewKeyFromString("hello", 32))
iv, _ := key.NewRandKey(a.BlockSize())
c := a.CBC(iv, vcipher.PKCS7Padding())

r, _ := c.EncryptData([]byte("hello how are you"))
r, _ = c.DecryptData(r)

t.Logf("%s", r)

Documentation

Index

Constants

View Source
const (
	// block
	AES_128 = "AES-128"
	AES_192 = "AES-192"
	AES_256 = "AES-256"
	DES     = "DES"
	TDES    = "3DES"

	// stream
	CHACHA20  = "CHACHA20"
	XCHACHA20 = "XCHACHA20"

	// aead
	CHACHA20_POLY1305  = "CHACHA20-POLY1305"
	XCHACHA20_POLY1305 = "CHACHA20-POLY1305"

	// mode
	CTR = "CTR"
)

Variables

This section is empty.

Functions

func GetAEADCipherFromString

func GetAEADCipherFromString(cip string, key []byte) (cipher.AEAD, error)

func GetBlockCipherFromCipherString

func GetBlockCipherFromCipherString(cip string, key []byte) (cipher.Block, error)

func GetStreamCipherFromCipherString

func GetStreamCipherFromCipherString(cip string, key, nonce []byte) (cipher.Stream, error)

func PaddingPKCS5

func PaddingPKCS5(src []byte, size int) []byte

func PaddingPKCS7

func PaddingPKCS7(src []byte, size int) []byte

func RegistAEAD

func RegistAEAD(cip string, getter AEADCipherGetter)

func RegistBlock

func RegistBlock(cip string, getter BlockCipherGetter)

func RegistStream

func RegistStream(cip string, getter StreamCipherGetter)

func UnPaddingPKCS5

func UnPaddingPKCS5(src []byte, size int) ([]byte, error)

func UnPaddingPKCS7

func UnPaddingPKCS7(src []byte, size int) ([]byte, error)

Types

type AEADCipherGetter

type AEADCipherGetter func(key []byte) (cip cipher.AEAD, err error)

type BlockCipherGetter

type BlockCipherGetter func(key []byte) (cip cipher.Block, err error)

type ModeGetter

type ModeGetter func(cip cipher.Block, iv []byte) (interface{}, error)

type Padder

type Padder func(src []byte, size int) []byte

type PadderPair

type PadderPair struct {
	P  Padder
	Un UnPadder
}

func PKCS5Padding

func PKCS5Padding() PadderPair

func PKCS7Padding

func PKCS7Padding() PadderPair

type StreamCipherGetter

type StreamCipherGetter func(key, nonce []byte) (cip cipher.Stream, err error)

type UnPadder

type UnPadder func(src []byte, size int) ([]byte, error)

type VAEAD

type VAEAD struct {
	cipher.AEAD
}

func (*VAEAD) DecryptData

func (v *VAEAD) DecryptData(ciphertext, nonce, additional []byte) ([]byte, error)

func (*VAEAD) EncryptData

func (v *VAEAD) EncryptData(plaintext, nonce, additional []byte) ([]byte, error)

type VBlock

type VBlock struct {
	cipher.Block
}

func Upgrade

func Upgrade(b cipher.Block) *VBlock

func (*VBlock) CBC

func (v *VBlock) CBC(iv []byte, pair PadderPair) *VBlockModePair

func (*VBlock) CFB

func (v *VBlock) CFB(iv []byte) *VStream

func (*VBlock) CTR

func (v *VBlock) CTR(iv []byte) cipher.Stream

func (*VBlock) DecryptData

func (v *VBlock) DecryptData(ciphertext []byte) ([]byte, error)

func (*VBlock) EncryptData

func (v *VBlock) EncryptData(plaintext []byte) ([]byte, error)

func (*VBlock) GCM

func (v *VBlock) GCM() (cipher.AEAD, error)

func (*VBlock) OFB

func (v *VBlock) OFB(iv []byte) cipher.Stream

type VBlockModePair

type VBlockModePair struct {
	E cipher.BlockMode
	D cipher.BlockMode
	// contains filtered or unexported fields
}

func NewVBlockMode

func NewVBlockMode(e, d cipher.BlockMode, p Padder, un UnPadder) *VBlockModePair

func (*VBlockModePair) DecryptData

func (v *VBlockModePair) DecryptData(ciphertext []byte) ([]byte, error)

func (*VBlockModePair) EncryptData

func (v *VBlockModePair) EncryptData(plaintext []byte) ([]byte, error)

type VCipher

type VCipher interface {
	EncryptData([]byte) ([]byte, error)
	DecryptData([]byte) ([]byte, error)
}

type VStream

type VStream struct {
	E cipher.Stream
	D cipher.Stream
}

func NewVStream

func NewVStream(e, d cipher.Stream) *VStream

func (*VStream) DecryptData

func (v *VStream) DecryptData(ciphertext []byte) ([]byte, error)

func (*VStream) EncryptData

func (v *VStream) EncryptData(plaintext []byte) ([]byte, error)

Directories

Path Synopsis
vblock
vstream

Jump to

Keyboard shortcuts

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