crypt

package
v0.0.0-...-ea7d51e Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ECB = iota
	CBC
	CFB
	OFB
)

Variables

This section is empty.

Functions

func DecodeString

func DecodeString(data string, encodedType Encode) ([]byte, error)

DecodeString decodes string data to bytes in designed encoded type

func EncodeToString

func EncodeToString(data []byte, encodeType Encode) (string, error)

EncodeToString encodes data to string with encode type

func GetHash

func GetHash(data []byte, hashType Hash) (h crypto.Hash, hashed []byte, err error)

GetHash gets the crypto hash type & hashed data in different hash type

func GetHashFunc

func GetHashFunc(hashType Hash) (f func() hash.Hash, h crypto.Hash)

GetHashFunc gets the crypto hash func & type in different hash type

func PKCS7Padding

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

PKCS7Padding adds padding data using pkcs7 rules , adapt to PKCS5 &PKCS7

func ParsePrivateKey

func ParsePrivateKey(data []byte, keyType Secret) (*rsa.PrivateKey, error)

ParsePrivateKey parses private key data to *rsa.PrivateKey

func UnPaddingPKCS7

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

UnPaddingPKCS7 un-padding src data to original data , adapt to PKCS5 & PKCS7

Types

type Cipher

type Cipher uint

type CipherCrypt

type CipherCrypt struct {
	Block cipher.Block
}

func (*CipherCrypt) Decrypt

func (cc *CipherCrypt) Decrypt(src []byte, c Cipher, ivs ...[]byte) (dst []byte, err error)

Decrypt decrypts src to dst with cipher & iv, if failed return error src the original encrypted bytes c the defined cipher type,now support CBC,CFB,OFB,ECB ivs the iv for CBC,CFB,OFB mode dst the decrypted bytes

func (*CipherCrypt) DecryptToString

func (cc *CipherCrypt) DecryptToString(encodeType Encode, src []byte, c Cipher, ivs ...[]byte) (dst string, err error)

DecryptToString decrypts src then encodes return data to string encodeType now support String,HEX,Base64

func (*CipherCrypt) Encrypt

func (cc *CipherCrypt) Encrypt(src []byte, c Cipher, ivs ...[]byte) (dst []byte, err error)

Encrypt encrypts src to dst with cipher & iv, if failed return error src the original source bytes c the defined cipher type,now support CBC,CFB,OFB,ECB ivs the iv for CBC,CFB,OFB mode dst the encrypted bytes

func (*CipherCrypt) EncryptToString

func (cc *CipherCrypt) EncryptToString(encodeType Encode, src []byte, c Cipher, ivs ...[]byte) (dst string, err error)

EncryptToString encrypts src then encodes data returned to string encodeType now support String,HEX,Base64

type Crypt

type Crypt uint
const (
	RSA Crypt = iota
)

type Encode

type Encode uint
const (
	String Encode = iota
	Hex
	Base64
)

type Hash

type Hash uint
const (
	// Bcrypt is the default hashing algorithm
	MD5 Hash = iota
	SHA1
	SHA224
	SHA256
	SHA384
	SHA512
	SHA512_224
	SHA512_256
)

type Padding

type Padding uint
const (
	PaddingPKCS5 Padding = iota
	PaddingPKCS7
)

type Secret

type Secret uint
const (
	PKCS1 Secret = iota
	PKCS8
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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