v0.3.0 Latest Latest

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

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



cipher package is a helper package for encrypting and decrypting messages



This section is empty.


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


type BasicHashLoader added in v0.3.0

type BasicHashLoader struct {
	HashName string

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 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) ([]byte, error)

Decrypt represents the ability to decrypt messages

type Enrypt added in v0.3.0

type Enrypt 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) ([]byte, error)

Enrypt represents the ability to encrypt messages

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 LoadConfig added in v0.3.0

type LoadConfig struct {
	Hash HashLoader
	Key  KeyLoader

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 *NOOP) DecryptMessage(cipher []byte) ([]byte, error)

func (*NOOP) EncryptMessage

func (noop *NOOP) EncryptMessage(message []byte) ([]byte, error)

func (*NOOP) Sign

func (noop *NOOP) Sign(message []byte) ([]byte, error)

func (*NOOP) VerifyMessage

func (noop *NOOP) VerifyMessage(message []byte, signature []byte) bool

type PrivateKeyCipher added in v0.3.0

type PrivateKeyCipher interface {

PrivateKeyCipher handles functionality provided with a privateKey

func LoadPrivate added in v0.3.0

func LoadPrivate(v *viper.Viper) (PrivateKeyCipher, error)

func LoadPrivateKey added in v0.3.0

func LoadPrivateKey(config LoadConfig) (PrivateKeyCipher, error)

func NewPrivateCrypter added in v0.3.0

func NewPrivateCrypter(hash crypto.Hash, key *rsa.PrivateKey) PrivateKeyCipher

type PublicKeyCipher added in v0.3.0

type PublicKeyCipher interface {

PrivateKeyCipher handles functionality provided with a publicKey

func LoadPublic added in v0.3.0

func LoadPublic(v *viper.Viper) (PublicKeyCipher, error)

func LoadPublicKey added in v0.3.0

func LoadPublicKey(config LoadConfig) (PublicKeyCipher, error)

func NewPublicCrypter added in v0.3.0

func NewPublicCrypter(hash crypto.Hash, key *rsa.PublicKey) PublicKeyCipher

type Sign added in v0.3.0

type Sign interface {
	// Sign attempts to sign the message into an array of bytes
	// and an error will be returned if a failure is encountered while signing the message.
	Sign(message []byte) ([]byte, error)

Sign is used to sign the signature of a message

type Verify

type Verify interface {
	// VerifyMessage will return true if the message was successfully verified
	VerifyMessage(message []byte, signature []byte) bool

Verify is used to sign and verify the signature of a message

Jump to

Keyboard shortcuts

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