encrypt

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EncryptHeaderV1 ...
	EncryptHeaderV1 = "<enc-v1>"
	// SHA1 is the name of sha1 hash alg
	SHA1 = "sha1"
	// SHA256 is the name of sha256 hash alg
	SHA256 = "sha256"
)

Variables

View Source
var HashAlg = map[string]func() hash.Hash{
	SHA1:   sha1.New,
	SHA256: sha256.New,
}

HashAlg used to get correct alg for hash

Functions

func Encrypt

func Encrypt(content string, salt string, encrptAlg string) string

Encrypt encrypts the content with salt

func ReversibleDecrypt

func ReversibleDecrypt(str, key string) (string, error)

ReversibleDecrypt decrypts the str with aes/base64 or base 64 depending on "header"

func ReversibleEncrypt

func ReversibleEncrypt(str, key string) (string, error)

ReversibleEncrypt encrypts the str with aes/base64

Types

type AESEncryptor

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

AESEncryptor uses AES to encrypt or decrypt string

func (*AESEncryptor) Decrypt

func (a *AESEncryptor) Decrypt(ciphertext string) (string, error)

Decrypt ...

func (*AESEncryptor) Encrypt

func (a *AESEncryptor) Encrypt(plaintext string) (string, error)

Encrypt ...

type Encryptor

type Encryptor interface {
	// Encrypt encrypts plaintext
	Encrypt(string) (string, error)
	// Decrypt decrypts ciphertext
	Decrypt(string) (string, error)
}

Encryptor encrypts or decrypts a strings

func AesInstance

func AesInstance() Encryptor

AesInstance ... Get instance of encryptor

func NewAESEncryptor

func NewAESEncryptor(keyProvider KeyProvider) Encryptor

NewAESEncryptor returns an instance of an AESEncryptor

type FileKeyProvider

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

FileKeyProvider reads key from file

func (*FileKeyProvider) Get

func (f *FileKeyProvider) Get(params map[string]interface{}) (string, error)

Get returns the key read from file

type KeyProvider

type KeyProvider interface {
	// Get returns the key
	// params can be used to pass parameters in different implements
	Get(params map[string]interface{}) (string, error)
}

KeyProvider provides the key used to encrypt and decrypt attrs

func NewFileKeyProvider

func NewFileKeyProvider(path string) KeyProvider

NewFileKeyProvider returns an instance of FileKeyProvider path: where the key should be read from

type PresetKeyProvider

type PresetKeyProvider struct {
	Key string
}

PresetKeyProvider returns the preset key disregarding the parm, this is for testing only

func (*PresetKeyProvider) Get

func (p *PresetKeyProvider) Get(params map[string]interface{}) (string, error)

Get ...

Jump to

Keyboard shortcuts

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