Categorygithub.com/KarpelesLab/cryptutil
modulepackage
0.2.30
Repository: https://github.com/karpeleslab/cryptutil.git
Documentation: pkg.go.dev

# README

GoDoc

cryptutil

Some tools for handling common crypto tasks not found in the go standard library

ECDH Message encryption

Sometimes you want to send a message. Sometimes you want it encrypted. Sending an encrypted message to a ECDSA key can be painful and come with all sorts of difficulties.

This library aims to provide a simple encryption/decryption scheme that just takes a plaintext and a key and returns an encrypted string.

The decryption function accepts any kind of ECDH handler, allowing the actual private key to be stored into a TPM or a HSM.

Bottle

Bottles are containers for arbitrary data (json, cbor, anything) that can be used to add any number of signatures, encryption layers etc to the underlying message, while keeping recovery of the original message fairly easy.

// Create a new bottle with a message inside
bottle := cryptutil.NewBottle([]byte("s.o.s. to the world"))

// encrypt for Alice OR Bob (either will be able to open the bottle)
bottle.Encrypt(rand.Reader, bob.Public(), alice.Public())
bottle.BottleUp() // bottle in a bottle, so that the signature includes the encryption
bottle.Sign(rand.Reader, alice) // sign from Alice

// Bob is opening the bottle
opener, err := cryptutil.NewOpener(bob)
res, info, err := opener.Open(bottle)
// first, check err to see if opening the bottle was successful
// Then you can inspect info to see which signatures were verified, and how many
// layers of encryption were decrypted

ID Card

ID Cards can be used by entities with a signing key to provide alternate encryption keys.

# Functions

AsCborBottle considers data to be a cbor-encoded Bottle, and will return a Bottle container matching this assumption.
AsJsonBottle considers data to be a json-encoded Bottle, and will return a Bottle container matching this assumption.
DecryptShortBuffer decrypts a given buffer.
ECDHDecrypt decrypts data received for us, using the private key passed (can be a tpm, etc).
ECDHEncrypt encrypts data for receiving by remote.
EncryptShortBuffer performs a simple encryption of a buffer.
Hash is a helper function to perform hashes on buffers, including multi-level hashing.
Marshal will use cbor to marshal data into a bottle.
MarshalJson will use json to marshal data into a bottle.
MemClr is a simple function that will clear a buffer in order to make it easier to reset memory storing private keys on defer.
MustOpener returns an opener that can be used to open a [Bottle] and panics if it fails.
NewBottle will return a new clean bottle only containing the provided data.
NewIDCard generates a new ID card for the given public key.
NewKeychain returns a new, empty keychain.
No description provided by the author
NewOpener returns an opener that can be used to open a [Bottle] using any or all of the given keys.
PublicKey returns the public key for a given private key, or nil if the argumlent is not a private key or if its Public() method returned nil.
Sign generates a signature for the given buffer.
Verify will verify the given buffer against the signature, depending on the key type.

# Constants

AES+AEAD encrypted cbor bottle.
bottle in a bottle.
No description provided by the author
bottle in a bottle (json version).

# Variables

EmptyOpener is an opener without any keys that can open bottles, but can't check keys.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

Bottle is a signed, encrypted message container.
IDCard is a basic ID for a given signature key that allows it to specify keys that can be used for encryption/etc.
Keychain is an object storing private keys that can be used to sign or decrypt things.
Membership is a membership in a group.
No description provided by the author
No description provided by the author
Opener allows opening a [Bottle].
No description provided by the author
SubKey is a key found in a given id card.

# Interfaces

No description provided by the author
PrivateKey represents a private key using an unspecified algorithm.
PublicKeyIntf represents a public key using an unspecified algorithm.

# Type aliases

No description provided by the author