encrypt

package module
v0.0.0-...-0942b9f Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2021 License: Apache-2.0 Imports: 7 Imported by: 1

README

encrypt

A functions wrapping of library for symmetric encryption and decryption

安装

go get -u github.com/18211167516/encrypt

使用

参考demo目录

Documentation

Index

Constants

View Source
const (
	AES_CBC  = "AES_CBC"
	AES_ECB  = "AES_ECB"
	AES_CFB  = "AES_CFB"
	DES_CBC  = "DES_CBC"
	DES_ECB  = "DES_ECB"
	DES_CFB  = "DES_CFB"
	DES3_CBC = "DES3_CBC"
	DES3_ECB = "DES3_ECB"
	DES3_CFB = "DES3_CFB"
)
View Source
const PKCS5_PADDING = "PKCS5"
View Source
const PKCS7_PADDING = "PKCS7"
View Source
const ZEROS_PADDING = "ZEROS"

Variables

View Source
var ErrIvLength16 = errors.New("invalid iv size must 16 bytes")
View Source
var ErrIvLength8 = errors.New("invalid iv size must 8 bytes")
View Source
var ErrNotFoundMode = errors.New("not found mode")

Functions

func AesDecryptCBC

func AesDecryptCBC(encrypted, key, iv []byte, padding string) (decrypted []byte, err error)

func AesDecryptCFB

func AesDecryptCFB(encrypted, key, iv []byte, padding string) (decrypted []byte, err error)

func AesDecryptECB

func AesDecryptECB(encrypted []byte, key []byte, padding string) (decrypted []byte, err error)

func AesEncryptCBC

func AesEncryptCBC(origData, key, iv []byte, padding string) (encrypted []byte, err error)

=================== CBC ======================

func AesEncryptCFB

func AesEncryptCFB(origData, key, iv []byte, padding string) (encrypted []byte, err error)

func AesEncryptECB

func AesEncryptECB(origData []byte, key []byte, padding string) (encrypted []byte, err error)

=================== ECB ======================

func DesDecryptCBC

func DesDecryptCBC(encrypted, key, iv []byte, padding string) (decrypted []byte, err error)

func DesDecryptCFB

func DesDecryptCFB(encrypted, key, iv []byte, padding string) (decrypted []byte, err error)

func DesDecryptECB

func DesDecryptECB(encrypted []byte, key []byte, padding string) (decrypted []byte, err error)

func DesEncryptCBC

func DesEncryptCBC(origData, key, iv []byte, padding string) (encrypted []byte, err error)

=================== CBC ======================

func DesEncryptCFB

func DesEncryptCFB(origData, key, iv []byte, padding string) (encrypted []byte, err error)

=================== CFB ======================

func DesEncryptECB

func DesEncryptECB(origData []byte, key []byte, padding string) (encrypted []byte, err error)

=================== ECB ======================

func PKCS5Padding

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

func PKCS5Unpadding

func PKCS5Unpadding(src []byte) []byte

func PKCS7Padding

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

func PKCS7UnPadding

func PKCS7UnPadding(src []byte) []byte

func Padding

func Padding(padding string, src []byte, blockSize int) []byte

func TripleDesDecryptCBC

func TripleDesDecryptCBC(encrypted, key, iv []byte, padding string) (decrypted []byte, err error)

func TripleDesDecryptCFB

func TripleDesDecryptCFB(encrypted, key, iv []byte, padding string) (decrypted []byte, err error)

func TripleDesDecryptECB

func TripleDesDecryptECB(encrypted []byte, key []byte, padding string) (decrypted []byte, err error)

func TripleDesEncryptCBC

func TripleDesEncryptCBC(origData, key, iv []byte, padding string) (encrypted []byte, err error)

=================== CBC ======================

func TripleDesEncryptCFB

func TripleDesEncryptCFB(origData, key, iv []byte, padding string) (encrypted []byte, err error)

=================== CFB ======================

func TripleDesEncryptECB

func TripleDesEncryptECB(origData []byte, key []byte, padding string) (encrypted []byte, err error)

=================== ECB ======================

func UnPadding

func UnPadding(padding string, src []byte) []byte

func ZerosPadding

func ZerosPadding(src []byte, blockSize int) []byte

func ZerosUnPadding

func ZerosUnPadding(src []byte) []byte

Types

type Encrypt

type Encrypt struct {
	Mode    string
	Key, Iv []byte
	Padding string
}

func NewEncrypt

func NewEncrypt(mode string, key, iv []byte, padding string) *Encrypt

实例化加密

func (*Encrypt) Base64Decrypt

func (en *Encrypt) Base64Decrypt(encrypted string) (decrypted []byte, err error)

传入base64格式字符串解密

func (*Encrypt) Decrypt

func (en *Encrypt) Decrypt(encrypted []byte) (decrypted []byte, err error)

################ Decrypt ##################

func (*Encrypt) Encrypt

func (en *Encrypt) Encrypt(origData []byte) (encrypted []byte, err error)

func (*Encrypt) EncryptBase64

func (en *Encrypt) EncryptBase64(origData []byte) string

加密生成base64格式的字符串

func (*Encrypt) EncryptHex

func (en *Encrypt) EncryptHex(origData []byte) string

加密生成hex格式的字符串

func (*Encrypt) HexDecrypt

func (en *Encrypt) HexDecrypt(encrypted string) (decrypted []byte, err error)

传入hex格式解密

Directories

Path Synopsis
demo module

Jump to

Keyboard shortcuts

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