naclwrapper

package
v0.0.0-...-cf48056 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2018 License: BSD-3-Clause Imports: 6 Imported by: 2

Documentation

Overview

Package naclwrapper implements easy to use NaCL encryption/decryption wrappers including binary packing/unpacking

Index

Constants

View Source
const (
	// RecipientPublicKey is the field marker for the recipient's public key
	RecipientPublicKey = iota + 1
	// SenderPublicKey is the field marker for the senders's public key
	SenderPublicKey
	// Nonce is the field marker for the NaCL nonce
	Nonce
	// NaCLBox is the field marker for the NaCL encrypted message
	NaCLBox
)

Variables

View Source
var (
	// ErrMissingKey is returned when neither sender nor recipient keys are given
	ErrMissingKey = errors.New("nacl wrapper: either sender or recipient key must be given")
	// ErrMissingPrivate is returned when no private key has been given
	ErrMissingPrivate = errors.New("nacl wrapper: no private key given")
	// ErrDataShort is returned if the packet could not containe a message
	ErrDataShort = errors.New("nacl wrapper: data short")
	// ErrNotRecipient is returned if the packet is not addressed to the private key
	ErrNotRecipient = errors.New("nacl wrapper: not addressed to recipient")
	// ErrDecryptFailed is returned if the packet could not been decrypted
	ErrDecryptFailed = errors.New("nacl wrapper: could not decrypt")
	// ErrFieldMissing is returned if the packed message is missing a field
	ErrFieldMissing = errors.New("nacl wrapper: missing field")
	// ErrEncryptToSelf is returned if both keys are the same
	ErrEncryptToSelf = errors.New("nacl wrapper: will not encrypt to self")
)

Functions

func Decrypt

func Decrypt(data []byte, rpubkey, rprivkey []byte) ([]byte, error)

Decrypt data with rprivkey. Rpubkey can be nil, it will be automatically generated

func DecryptPack

func DecryptPack(data []byte, rpubkey, rprivkey []byte) ([]byte, error)

DecryptPack decrypts an encrypted bytepack

func Encrypt

func Encrypt(data []byte, rpubkey, spubkey, sprivkey []byte) ([]byte, error)

Encrypt data with given keys. If any of the keys is not given it will be generated. At least one of rpubkey or sprivkey MUST be present (otherwise it would be an encryption that cannot be decrypted anymore)

func EncryptPack

func EncryptPack(data []byte, rpubkey, spubkey, sprivkey []byte) ([]byte, error)

EncryptPack creates an encrypted bytepack

Types

type NaCLKeyPair

type NaCLKeyPair struct {
	PublicKey  []byte // Public key
	PrivateKey []byte // Private key
}

NaCLKeyPair contains a NaCL key

Jump to

Keyboard shortcuts

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