encryption

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2021 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PaddingPKCS5 = iota
	PaddingPKCS7
)
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 GenRsaKey

func GenRsaKey(bits int) ([]byte, []byte, error)

GenRsaKey return publicKey, privateKey, error

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(cipherText []byte, blockSize int) []byte

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

func ParsePrivateKey

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

ParsePrivateKey parses private key bytes to rsa privateKey

func UnPaddingPKCS7

func UnPaddingPKCS7(src []byte) []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

Crypt defines crypt types

const (
	RSA Crypt = iota
)

type Encode

type Encode uint

Encode defines the type of bytes encoded to string

const (
	String Encode = iota
	HEX
	Base64
)

type EnvEncrypt

type EnvEncrypt struct {
	// contains filtered or unexported fields
}

Encrypt encrypt 实例对象封装

func New

func New(options ...Option) *EnvEncrypt

New 新建 Encrypt service

func (*EnvEncrypt) DecryptAddonConfigMap

func (e *EnvEncrypt) DecryptAddonConfigMap(configMap *map[string]interface{}) error

encryptConfigMap 解密环境变量中password信息

func (*EnvEncrypt) DecryptPassword

func (e *EnvEncrypt) DecryptPassword(src string) (string, error)

encryptConfigMap 解密

func (*EnvEncrypt) EncryptPassword

func (e *EnvEncrypt) EncryptPassword(src string) (string, error)

encryptConfigMap 加密

type Hash

type Hash uint

Hash for crypto Hash

const (
	MD5 Hash = iota
	SHA1
	SHA224
	SHA256
	SHA384
	SHA512
	SHA512_224
	SHA512_256
)

type Option

type Option func(*EnvEncrypt)

Option Migration 实例对象配置选项

func WithRSAScrypt

func WithRSAScrypt(rsaScrypt *RsaCrypt) Option

WithRSAScrypt 配置 RsaCrypt

type Padding

type Padding uint

type RSASecret

type RSASecret struct {
	PublicKey          string
	PublicKeyDataType  Encode
	PrivateKey         string
	PrivateKeyDataType Encode
	PrivateKeyType     Secret
}

type RsaCrypt

type RsaCrypt struct {
	// contains filtered or unexported fields
}

func NewRSAScrypt

func NewRSAScrypt(secretInfo RSASecret) *RsaCrypt

NewRSACrypt init with the RSA secret info

func (*RsaCrypt) Decrypt

func (rc *RsaCrypt) Decrypt(src string, srcType Encode) (dst string, err error)

Decrypt decrypts a plaintext using private key src the encrypted data with public key srcType the encode type of encrypted data ,such as Base64,HEX

func (*RsaCrypt) Encrypt

func (rc *RsaCrypt) Encrypt(src string, outputDataType Encode) (dst string, err error)

Encrypt encrypts the given message with public key src the original data outputDataType the encode type of encrypted data ,such as Base64,HEX

type Secret

type Secret uint

Secret defines the private key type

const (
	PKCS1 Secret = iota
	PKCS8
)

Jump to

Keyboard shortcuts

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