crypt

package
v0.0.0-...-edbd301 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2019 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadAndDecodeKey

func LoadAndDecodeKey(d *deps.Dependencies, filename string) (PEMEncoded, X509Encoded, error)

LoadAndDecodeKey loads PEM encoded file and decodes it into a x509 encoded key block. Returns PEM encoded data with key block.

Types

type AlgorithmPlugin

type AlgorithmPlugin interface {
	GenKeyPair(randReader io.Reader) (pubKey X509Encoded, privKey X509Encoded, err error)
	InjestPrivateKey(privKey X509Encoded) (signer crypto.Signer, err error)
	VerifySignature(sha256Hash DigestHash, binSig BinarySignature, publicKey crypto.PublicKey) (bool, error)
	GetAlgorithmName() string
}

AlgorithmPlugin is used to encapsulate algorithm specific code.

type BinarySignature

type BinarySignature []byte

BinarySignature data buffer

func NewBinarySignatureFromBase64

func NewBinarySignatureFromBase64(src string) (BinarySignature, error)

NewBinarySignatureFromBase64 creates a new BinarySignature buffer from a base64 string.

func (BinarySignature) Base64

func (sig BinarySignature) Base64() string

Base64 renders the signature as a RFC 4648 compliant Base64 encoded string.

type CryptoTooling

type CryptoTooling struct {
	D         *deps.Dependencies
	Settings  *PkiSettings
	AlgPlugin AlgorithmPlugin
	PubKey    PEMEncoded
	PrivKey   PEMEncoded
	Signer    crypto.Signer
}

CryptoTooling home to all crypto tool state.

func GetCryptoTooling

func GetCryptoTooling(d *deps.Dependencies, keySettings *PkiSettings) (*CryptoTooling, error)

GetCryptoTooling returns a home where all the keys, signing and verification lives.

func (*CryptoTooling) PopulateKeys

func (ct *CryptoTooling) PopulateKeys() error

PopulateKeys populates the public and private keypair into ct from the filesystem, generating and storing keypair if missing.

func (*CryptoTooling) Sign

func (ct *CryptoTooling) Sign(digest DigestHash) (BinarySignature, error)

Sign is a thin wrapper over cryptoSigner.Sign() to ease type conversions and dependencies.

func (*CryptoTooling) SignMessage

func (ct *CryptoTooling) SignMessage(msg string) (BinarySignature, error)

SignMessage simply sighs a hash of the message. It was added for consistancy with VerifySignedMessage.

func (*CryptoTooling) VerifySignedMessage

func (ct *CryptoTooling) VerifySignedMessage(msg string, base64Sig string, pemPubKey string) (bool, error)

VerifySignedMessage simply sighs a hash of the message. It was added for consistancy with VerifySignedMessage.

type DigestHash

type DigestHash []byte

DigestHash data buffer

func NewSHA256DigestHash

func NewSHA256DigestHash(data string) DigestHash

NewSHA256DigestHash hashes the provided string buffer, This is a thin wrapper over crypto/sha256.Sum256()

func (DigestHash) Hex

func (hash DigestHash) Hex() string

Hex renders the hash digest as a hex string. This is primarily for debugging and error messages.

type ECDSAPlugin

type ECDSAPlugin struct{}

ECDSAPlugin Implementation details for ECDSA.

func (*ECDSAPlugin) GenKeyPair

func (p *ECDSAPlugin) GenKeyPair(randReader io.Reader) (pubKey X509Encoded, privKey X509Encoded, err error)

GenKeyPair generates a new ECDSA public and private key pair

func (*ECDSAPlugin) GetAlgorithmName

func (p *ECDSAPlugin) GetAlgorithmName() string

GetAlgorithmName returns the string "ECDSA"

func (*ECDSAPlugin) InjestPrivateKey

func (p *ECDSAPlugin) InjestPrivateKey(privKey X509Encoded) (signer crypto.Signer, err error)

InjestPrivateKey loads a ECDSA private key from a X509Encoded buffer,

func (*ECDSAPlugin) VerifySignature

func (p *ECDSAPlugin) VerifySignature(sha256Hash DigestHash, binSig BinarySignature, publicKey crypto.PublicKey) (bool, error)

VerifySignature verifies a ECDSA signature for a message digest,

type KeyType

type KeyType int

KeyType indicates if the key is public or private

const (
	PublicKey KeyType = iota
	PrivateKey
)

PublicKey indicates a public key

func (KeyType) String

func (t KeyType) String() string

type PEMEncoded

type PEMEncoded []byte

PEMEncoded text data buffer

func EncodeAndSaveKey

func EncodeAndSaveKey(
	d *deps.Dependencies,
	keyBuf X509Encoded,
	algorithm string,
	kt KeyType,
	filename string,
	perm os.FileMode,
) (PEMEncoded, error)

EncodeAndSaveKey PEM encodes a x509 encoded key and writes it to a file. Returns the PEM encoded string data.

func NewPEMBufferFromString

func NewPEMBufferFromString(src string) PEMEncoded

NewPEMBufferFromString turns a string into a PEM buffer.

func (PEMEncoded) DecodeToX509

func (pemBuf PEMEncoded) DecodeToX509() (X509Encoded, error)

DecodeToX509 decodes the PEM key data block to a x509 buffer

func (PEMEncoded) String

func (pemBuf PEMEncoded) String() string

String renders the PEM encoded data as a string.

type PkiSettings

type PkiSettings struct {
	Algorithm      x509.PublicKeyAlgorithm
	RSAKeyBits     int
	PrivateKeyPath string
	PublicKeyPath  string
}

PkiSettings are the public key settings as specified on the command line.

type RSAPlugin

type RSAPlugin struct {
	KeyLen int
}

RSAPlugin Implementation details for RSA.

func (*RSAPlugin) GenKeyPair

func (p *RSAPlugin) GenKeyPair(randReader io.Reader) (pubKey X509Encoded, privKey X509Encoded, err error)

GenKeyPair generates a new RSA public and private key pair

func (*RSAPlugin) GetAlgorithmName

func (p *RSAPlugin) GetAlgorithmName() string

GetAlgorithmName returns the string "RSA"

func (*RSAPlugin) InjestPrivateKey

func (p *RSAPlugin) InjestPrivateKey(privKey X509Encoded) (signer crypto.Signer, err error)

InjestPrivateKey loads a RSA private key from a X509Encoded buffer,

func (*RSAPlugin) VerifySignature

func (p *RSAPlugin) VerifySignature(sha256Hash DigestHash, binSig BinarySignature, publicKey crypto.PublicKey) (bool, error)

VerifySignature verifies a RSA signature for a message digest,

type X509Encoded

type X509Encoded []byte

X509Encoded data buffer

func (X509Encoded) AsGenericPublicKey

func (x X509Encoded) AsGenericPublicKey() (crypto.PublicKey, error)

AsGenericPublicKey decodes the public key (if it is one)

func (X509Encoded) EncodeToPEM

func (x X509Encoded) EncodeToPEM(algorithm string, kt KeyType) PEMEncoded

EncodeToPEM encodes the x509 key as a PEM text block

Jump to

Keyboard shortcuts

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