cryptography

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2022 License: MIT Imports: 16 Imported by: 1

Documentation

Index

Constants

View Source
const (
	KMS_DATA_KEY_LENGTH int32  = 32
	CRYPTO_KEY_KMS      string = "KMS"
)
View Source
const (
	CRYPTO_KEY_SM string = "SECMAN"
)

Variables

View Source
var (
	EnvelopeRegex = regexp.MustCompile(regexstr)
)

Functions

func AsNaCLKey

func AsNaCLKey(data []byte) (*[32]byte, error)

Converts a byte slice to a [32]byte as expected by NaCL

func DecryptEnvelopes added in v1.2.0

func DecryptEnvelopes(input string, strategy Decryptor) (output string, err error)

func ExtractEncryptionType

func ExtractEncryptionType(input string) string

func UnwrapEncoding

func UnwrapEncoding(input string) ([]byte, error)

func WrapEncoding

func WrapEncoding(key string, message []byte) string

Types

type Decryptor

type Decryptor interface {
	Key() string
	Decrypt(string) ([]byte, error)
}

Decryptor defines the contract for decrypting data

type Encryptor

type Encryptor interface {
	Key() string
	Encrypt([]byte) (string, error)
}

Encryptor defines the contract for encrypting data

type KmsCryptoStrategy

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

KmsCryptoStrategy handles AWS KMS based encryption and decryption

func NewKmsCryptoStrategy

func NewKmsCryptoStrategy(region string) (*KmsCryptoStrategy, error)

func (KmsCryptoStrategy) Decrypt

func (cs KmsCryptoStrategy) Decrypt(input string) ([]byte, error)

func (KmsCryptoStrategy) Encrypt

func (cs KmsCryptoStrategy) Encrypt(payload []byte, key string) (string, error)

func (*KmsCryptoStrategy) GenerateDataKey

func (cs *KmsCryptoStrategy) GenerateDataKey(keyId string) (*[32]byte, []byte, error)

func (KmsCryptoStrategy) Key added in v1.2.0

func (cs KmsCryptoStrategy) Key() string

type SecretsManagerCryptoStrategy added in v1.1.0

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

func NewSecretsManagerCryptoStrategy added in v1.1.0

func NewSecretsManagerCryptoStrategy(region string) (*SecretsManagerCryptoStrategy, error)

func (SecretsManagerCryptoStrategy) Decrypt added in v1.1.0

func (cs SecretsManagerCryptoStrategy) Decrypt(input string) ([]byte, error)

Decrypt will pull the secret from Secrets Manager

func (SecretsManagerCryptoStrategy) Encrypt added in v1.1.0

func (cs SecretsManagerCryptoStrategy) Encrypt(payload []byte, key string) (string, error)

Encrypt will generate the wrapped encoded string

@param: payload is expected to be the key of the secret that will be used for decryption
@param: key is used for key/value pair keys
@returns: The base64 encoded arn with the encryption strategy key

func (SecretsManagerCryptoStrategy) Key added in v1.2.0

type StrategyBuilder added in v1.2.0

type StrategyBuilder func() (Decryptor, error)

type WildcardDecryptionStrategy

type WildcardDecryptionStrategy struct {
	Strategies map[string]Decryptor
}

func NewWildcardDecryptionStrategy

func NewWildcardDecryptionStrategy(builders []StrategyBuilder) (*WildcardDecryptionStrategy, error)

NewWildcardDecryptionStrategy is the initializer function for WildcardDecryptionStrategy

func (*WildcardDecryptionStrategy) Add

Add is a builder function to build up any applicable decryption strategies

func (WildcardDecryptionStrategy) Decrypt

func (wds WildcardDecryptionStrategy) Decrypt(input string) ([]byte, error)

Decrypt will process the input string for the correct strategy and run decrypt on that strategy

func (WildcardDecryptionStrategy) Key added in v1.2.0

Jump to

Keyboard shortcuts

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