encryption

package
v0.0.0-...-386a0b5 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package encryption provides methods for deterministic encryption, a wrapper type EncryptedString for transparent encryption/decryption of strings during database operations and custom JSON marshaller/unmarshaller for correct serialization/unserialization.

Index

Constants

This section is empty.

Variables

View Source
var (

	// Disabled indicates if encryption is disabled
	Disabled bool
)

Functions

func Decrypt

func Decrypt(cryptoText string) (string, error)

Decrypt base64-decodes and then AES decrypts the given string

func Encrypt

func Encrypt(text string) (string, error)

Encrypt AES-encrypts the given string and then base64-encode's it

func SetKey

func SetKey(secretKey []byte) error

SetKey sets encryption key

Types

type EncryptedString

type EncryptedString struct {
	S string
}

EncryptedString is a wrappper around plain string allowing it to be transparently encrypted and decrypted

func (EncryptedString) Equals

func (es EncryptedString) Equals(estr EncryptedString) bool

Equals tells if this ecrypted string is the same as the given encrypted string

func (*EncryptedString) MarshalJSON

func (es *EncryptedString) MarshalJSON() ([]byte, error)

MarshalJSON marshals nested cleartext string

func (*EncryptedString) Scan

func (es *EncryptedString) Scan(value interface{}) error

Scan implements sql.Scanner and decryptes incoming sql column data

func (EncryptedString) String

func (es EncryptedString) String() string

func (*EncryptedString) UnmarshalJSON

func (es *EncryptedString) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals string into S var

func (EncryptedString) Value

func (es EncryptedString) Value() (value driver.Value, err error)

Value implements driver.Valuer and encrypts outgoing bind values

Jump to

Keyboard shortcuts

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