Documentation
¶
Overview ¶
cipher package is a helper package for encrypting and decrypting messages
Index ¶
- Constants
- func GeneratePrivateKey(size int) *rsa.PrivateKey
- func GetHash(hashType string) crypto.Hash
- func GetPrivateKey(loader KeyLoader) (*rsa.PrivateKey, error)
- func GetPublicKey(loader KeyLoader) (*rsa.PublicKey, error)
- type AlgorithmType
- type BasicHashLoader
- type BoxLoader
- type BytesLoader
- type Ciphers
- type Config
- type Decrypt
- type DecryptLoader
- type Encrypt
- type EncryptLoader
- type FileLoader
- type HashLoader
- type Identification
- type KeyLoader
- type KeyType
- type LocalCerts
- type NOOP
- type Options
- type RSALoader
Constants ¶
const ( // CipherKey is the Viper subkey under which logging should be stored. // NewOptions *does not* assume this key. CipherKey = "cipher" )
Variables ¶
This section is empty.
Functions ¶
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 GetPrivateKey ¶
func GetPrivateKey(loader KeyLoader) (*rsa.PrivateKey, error)
GetPrivateKey uses a keyloader to load a private key.
Types ¶
type AlgorithmType ¶
type AlgorithmType string
AlgorithmType is an enum used to specify which algorithm is being used.
const ( None AlgorithmType = "none" Box AlgorithmType = "box" RSASymmetric AlgorithmType = "rsa-sym" RSAAsymmetric AlgorithmType = "rsa-asy" )
func ParseAlgorithmType ¶
func ParseAlgorithmType(algo string) AlgorithmType
ParseAlgorithmType takes a string and returns an enum if one matches, otherwise returns the None AlgorithmType enum.
type BasicHashLoader ¶
type BasicHashLoader struct {
HashName string `mapstructure:"hash"`
}
BasicHashLoader implements HashLoader.
type BoxLoader ¶
BoxLoader loads the box encryption/decryption.
func (*BoxLoader) LoadDecrypt ¶
LoadDecrypt loads a decrypter for the box algorithm.
func (*BoxLoader) LoadEncrypt ¶
LoadEncrypt loads an encrypter for the box algorithm.
type BytesLoader ¶
type BytesLoader struct {
Data []byte
}
BytesLoader implements the KeyLoader.
func (*BytesLoader) GetBytes ¶
func (b *BytesLoader) GetBytes() ([]byte, error)
GetBytes returns the bytes stored by the BytesLoader
type Ciphers ¶
type Ciphers struct {
Options map[AlgorithmType]map[string]Decrypt
}
Ciphers provide all of the possibly algorithms that can be used to encrypt or decrypt.
func PopulateCiphers ¶
PopulateCiphers takes options and a logger and creates ciphers from them.
type Config ¶
type Config 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:"-"` // Type is the algorithm type. Like none, box, rsa etc. Type AlgorithmType `json:"type"` // KID is the key id of the cipher KID string `json:"kid,omitempty"` // Params to be provided to the algorithm type. // For example providing a hash algorithm to rsa. Params map[string]string `json:"params,omitempty"` // Keys is a map of keys to path. aka senderPrivateKey : private.pem Keys map[KeyType]string `json:"keys,omitempty"` }
Config used load the Encrypt or Decrypt
func (*Config) LoadDecrypt ¶
LoadDecrypt uses the config to load a decrypter.
func (*Config) LoadEncrypt ¶
LoadEncrypt uses the config to load an encrypter.
type Decrypt ¶
type Decrypt interface { Identification // 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 ¶
func DefaultCipherDecrypter() Decrypt
DEfaultCipherDecrypter returns a NOOP decrypter.
func NewBoxDecrypter ¶
NewBoxDecrypter returns a new box decrypter.
func NewRSADecrypter ¶
func NewRSADecrypter(hash crypto.Hash, recipientPrivateKey *rsa.PrivateKey, senderPublicKey *rsa.PublicKey, kid string) Decrypt
NewRSADecrypter returns an RSA decrypter.
type DecryptLoader ¶
DecryptLoader loads a decrypter.
type Encrypt ¶
type Encrypt interface { Identification // 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 ¶
func DefaultCipherEncrypter() Encrypt
DefaultCipherEncrypter returns a NOOP encrypter.
func NewBoxEncrypter ¶
NewBoxEncrypter returns a new box encrypter.
func NewRSAEncrypter ¶
func NewRSAEncrypter(hash crypto.Hash, senderPrivateKey *rsa.PrivateKey, recipientPublicKey *rsa.PublicKey, kid string) Encrypt
NewRSAEncrypter returns an RSA encrypter.
type EncryptLoader ¶
EncryptLoader loads an encrypter.
type FileLoader ¶
type FileLoader struct {
Path string
}
FileLoader loads a key from a file.
func (*FileLoader) GetBytes ¶
func (f *FileLoader) GetBytes() ([]byte, error)
GetBytes returns the bytes found at the filepath.
type HashLoader ¶
HashLoader can get a hash.
type Identification ¶
type Identification interface { // GetAlgorithm will return the algorithm Encrypt and Decrypt uses GetAlgorithm() AlgorithmType // GetKID returns the id of the specific keys used GetKID() string }
type LocalCerts ¶
LocalCerts specify where locally to find the certs for a hash.
type NOOP ¶
type NOOP struct{}
NOOP will just return the message
func (*NOOP) DecryptMessage ¶
DecryptMessage simply returns the message given.
func (*NOOP) EncryptMessage ¶
EncryptMessage simply returns the message given.
type Options ¶
type Options []Config
Options is the list of configurations used to load ciphers.
type RSALoader ¶
type RSALoader struct { KID string Hash HashLoader PrivateKey KeyLoader PublicKey KeyLoader }
RSALoader loads the encrypter/decrypter for the RSA algorithm.
func (*RSALoader) LoadDecrypt ¶
LoadDecrypt loads the RSA decrypter.
func (*RSALoader) LoadEncrypt ¶
LoadEncrypt loads the RSA encrypter.