secutil

package
v0.6.17 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package secutil provide some security utils

Index

Constants

View Source
const (
	CryptAes128CBC = "aes-128-cbc"
	CryptAes256CBC = "aes-256-cbc"
)

aes methods

View Source
const (
	PadTypeNone uint8 = iota
	PadTypeZeros
	PadTypePKCS5
	PadTypePKCS7
)

padding type for encoding contents.

Variables

View Source
var ErrUnPadding = errors.New("un-padding decrypted data fail")

ErrUnPadding error

Functions

func PKCS5Padding

func PKCS5Padding(ciphertext []byte, blockSize int) []byte

PKCS5Padding input data

func PKCS5UnPadding

func PKCS5UnPadding(origData []byte) ([]byte, error)

PKCS5UnPadding input data

func PKCS7Padding

func PKCS7Padding(ciphertext []byte, blockSize int) []byte

PKCS7Padding input data

func PKCS7UnPadding

func PKCS7UnPadding(origData []byte) ([]byte, error)

PKCS7UnPadding input data

Types

type AesCrypt

type AesCrypt struct {
	CryptConfig
	// contains filtered or unexported fields
}

AesCrypt struct

func NewAesCrypt

func NewAesCrypt() *AesCrypt

NewAesCrypt instance

func (*AesCrypt) Config

func (p *AesCrypt) Config(fn func(c *CryptConfig)) *AesCrypt

Config crypt instance

func (*AesCrypt) Decrypt

func (p *AesCrypt) Decrypt(enc []byte) ([]byte, error)

Decrypt an encrypt to source data

func (*AesCrypt) DecryptString

func (p *AesCrypt) DecryptString(enc string) (string, error)

DecryptString to source string. return error on fail.

func (*AesCrypt) Encrypt

func (p *AesCrypt) Encrypt(src []byte) ([]byte, error)

Encrypt input source bytes. return error on fail.

func (*AesCrypt) EncryptString

func (p *AesCrypt) EncryptString(src string) (string, error)

EncryptString to encoded string. return error on fail.

func (*AesCrypt) Init

func (p *AesCrypt) Init() error

Init crypt instance

type CryptConfig

type CryptConfig struct {
	Key string
	// IV string, length must be equals to cipher.Block.BlockSize()
	IV string
	// Method name. eg: CryptAes256CBC
	Method string
	// PadType for padding string.
	PadType uint8
	Encoder byteutil.BytesEncoder
}

CryptConfig struct

Jump to

Keyboard shortcuts

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