crypto

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2019 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EnvKeyName           = "KUBEKIT_KEY"
	KeyValidRules        = "A key should have 16, 24 or 32 characters, should contain at least one number and at least one uppercase and lowercase letter"
	DefaultKeyPassphrase = "S3cr3t%PassW0rd!"
)

EnvKeyName is the name of the environment variable to store the key KeyValidLen is the valid length for a key. A valid key should have an equal or larger length than KeyValidLen

Variables

This section is empty.

Functions

func IsDecrypted

func IsDecrypted(text string) bool

IsDecrypted returns true if the given text has the action to encrypt, returns true if it's decrypted/plaintext

func IsEncrypted

func IsEncrypted(text string) bool

IsEncrypted returns true if the given text has the action to decrypt, returns true if it's encrypted

func ValidKey

func ValidKey(key []byte) bool

ValidKey returns true if this is a valid key

Types

type Action

type Action int

Action defines an action like encrypt or decrypt

const (
	ActionDec Action = 1 << iota
	ActionEnc
	ActionUnknown
)

Defines all the possible CryptoActions

func ParseAction

func ParseAction(text string) Action

ParseAction returns the action to execute with the given text

func (Action) String

func (a Action) String() string

String returns the text to identify a CryptoAction

type Crypto

type Crypto struct {
	Key []byte
}

Crypto is a struct to handle cryptography (encryption/decryption)

func New

func New(key []byte) (*Crypto, error)

New creates a crypto struct to manage cryptography

func (*Crypto) Decrypt

func (c *Crypto) Decrypt(cryptotext string) ([]byte, error)

Decrypt decrypts an encrypted text using the given key

func (*Crypto) DecryptValue

func (c *Crypto) DecryptValue(cryptotext string) ([]byte, error)

DecryptValue decrypts an encrypted text using the given key and returns it in the configuration format

func (*Crypto) Encrypt

func (c *Crypto) Encrypt(plaintext []byte) (string, error)

Encrypt encrypts a plain text using the given key

func (*Crypto) EncryptValue

func (c *Crypto) EncryptValue(plaintext []byte) (string, error)

EncryptValue encrypts a plain text using the given key and returns it in the configuration format

func (*Crypto) Process

func (c *Crypto) Process(text string) (string, error)

Process either encrypt or decryt based on the action/function as text preffix

type KeyError

type KeyError []byte

KeyError is the error for an invalid key

func (KeyError) Error

func (ke KeyError) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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