v0.3.3 Latest Latest

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

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



cipher package is a helper package for encrypting and decrypting messages



View Source
const (
	// CipherKey is the Viper subkey under which logging should be stored.
	// NewOptions *does not* assume this key.
	CipherKey = "cipher"


This section is empty.


func GeneratePrivateKey

func GeneratePrivateKey(size int) *rsa.PrivateKey

GeneratePrivateKey will create a private key with the size given size must be greater than 64 or else it will default to 64.

Careful with the size, if its too large it won't encrypt the message or take forever

func GetHash added in v0.3.0

func GetHash(hashType string) crypto.Hash

func GetPrivateKey added in v0.3.2

func GetPrivateKey(loader KeyLoader) (*rsa.PrivateKey, error)

func GetPublicKey added in v0.3.2

func GetPublicKey(loader KeyLoader) (*rsa.PublicKey, error)

func Sub added in v0.3.2

func Sub(v *viper.Viper) *viper.Viper

Sub returns the standard child Viper, using CipherKey, for this package. If passed nil, this function returns nil.


type BasicHashLoader added in v0.3.0

type BasicHashLoader struct {
	HashName string `mapstructure:"hash"`

func (*BasicHashLoader) GetHash added in v0.3.0

func (b *BasicHashLoader) GetHash() (crypto.Hash, error)

GetHash return the given hash from hashFunctions if not found it will return an error.

0 is an invalid hash

type BasicLoader added in v0.3.2

type BasicLoader struct {
	Hash       HashLoader
	PrivateKey KeyLoader
	PublicKey  KeyLoader

func (*BasicLoader) LoadDecrypt added in v0.3.2

func (loader *BasicLoader) LoadDecrypt() (Decrypt, error)

func (*BasicLoader) LoadEncrypt added in v0.3.2

func (loader *BasicLoader) LoadEncrypt() (Encrypt, error)

type BoxLoader added in v0.3.2

type BoxLoader struct {
	PrivateKey KeyLoader
	PublicKey  KeyLoader

func (*BoxLoader) LoadDecrypt added in v0.3.2

func (boxLoader *BoxLoader) LoadDecrypt() (Decrypt, error)

func (*BoxLoader) LoadEncrypt added in v0.3.2

func (boxLoader *BoxLoader) LoadEncrypt() (Encrypt, error)

type BytesLoader added in v0.3.3

type BytesLoader struct {
	Data []byte

func (*BytesLoader) GetBytes added in v0.3.3

func (b *BytesLoader) GetBytes() ([]byte, error)

type Decrypt added in v0.3.0

type Decrypt interface {
	// DecryptMessage attempts to decode the message into a string.
	// and error will be returned if failed to decode the message.
	DecryptMessage(cipher []byte, nonce []byte) (message []byte, err error)

Decrypt represents the ability to decrypt messages

func DefaultCipherDecrypter added in v0.3.2

func DefaultCipherDecrypter() Decrypt

func NewBasicDecrypter added in v0.3.2

func NewBasicDecrypter(hash crypto.Hash, recipientPrivateKey *rsa.PrivateKey, senderPublicKey *rsa.PublicKey) Decrypt

func NewBoxDecrypter added in v0.3.2

func NewBoxDecrypter(recipientPrivateKey [32]byte, senderPublicKey [32]byte) Decrypt

type DecryptLoader added in v0.3.2

type DecryptLoader interface {
	LoadDecrypt() (Decrypt, error)

type Encrypt added in v0.3.2

type Encrypt interface {
	// EncryptMessage attempts to encode the message into an array of bytes.
	// and error will be returned if failed to encode the message.
	EncryptMessage(message []byte) (crypt []byte, nonce []byte, err error)

Encrypt represents the ability to encrypt messages

func DefaultCipherEncrypter added in v0.3.2

func DefaultCipherEncrypter() Encrypt

func NewBasicEncrypter added in v0.3.2

func NewBasicEncrypter(hash crypto.Hash, senderPrivateKey *rsa.PrivateKey, recipientPublicKey *rsa.PublicKey) Encrypt

func NewBoxEncrypter added in v0.3.2

func NewBoxEncrypter(senderPrivateKey [32]byte, recipientPublicKey [32]byte) Encrypt

type EncryptLoader added in v0.3.2

type EncryptLoader interface {
	LoadEncrypt() (Encrypt, error)

type FileLoader added in v0.3.0

type FileLoader struct {
	Path string

func (*FileLoader) GetBytes added in v0.3.0

func (f *FileLoader) GetBytes() ([]byte, error)

type HashLoader added in v0.3.0

type HashLoader interface {
	GetHash() (crypto.Hash, error)

type KeyLoader added in v0.3.0

type KeyLoader interface {
	GetBytes() ([]byte, error)

type LocalCerts added in v0.3.0

type LocalCerts struct {
	Path     string
	HashName string

type NOOP

type NOOP struct{}

NOOP will just return the message

func (*NOOP) DecryptMessage

func (*NOOP) DecryptMessage(cipher []byte, nonce []byte) (message []byte, err error)

func (*NOOP) EncryptMessage

func (*NOOP) EncryptMessage(message []byte) (crypt []byte, nonce []byte, err error)

type Options added in v0.3.2

type Options struct {
	// Logger is the go-kit Logger to use for server startup and error logging.  If not
	// supplied, logging.DefaultLogger() is used instead.
	Logger log.Logger `json:"-"`

	Algorithm map[string]interface{} `json:"algorithm,omitempty"`

	SenderPrivateKey    string `json:"senderPrivateKey,omitempty"`
	SenderPublicKey     string `json:"senderPublicKey,omitempty"`
	RecipientPrivateKey string `json:"recipientPrivateKey,omitempty"`
	RecipientPublicKey  string `json:"recipientPublicKey,omitempty"`

func FromViper added in v0.3.2

func FromViper(v *viper.Viper) (*Options, error)

FromViper produces an Options from a (possibly nil) Viper instance. Callers should use FromViper(Sub(v)) if the standard subkey is desired.

func (*Options) LoadDecrypt added in v0.3.2

func (o *Options) LoadDecrypt() (Decrypt, error)

func (*Options) LoadEncrypt added in v0.3.2

func (o *Options) LoadEncrypt() (Encrypt, error)


Path Synopsis

Jump to

Keyboard shortcuts

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