keybox

package
v0.0.0-...-4eea697 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Wrapper around golang.org/x/crypto/nacl/box for easy use with KeyLength-byte keys

Index

Constants

View Source
const (
	KeyLength   = 32
	NonceLength = 24
)

Variables

This section is empty.

Functions

func GenerateNonce

func GenerateNonce() (*[NonceLength]byte, error)

Generate random nonce to use with Seal*

func Open

func Open(encrypted []byte, peersPublicKey, privateKey *[KeyLength]byte) ([]byte, error)

Open authenticates and decrypts a message produced by Seal

func OpenAfterPrecomputation

func OpenAfterPrecomputation(encrypted []byte, sharedKey *[KeyLength]byte) ([]byte, error)

OpenAfterPrecomputation performs the same actions as Open, but takes a shared key as generated by Precompute.

func OpenAnonymous

func OpenAnonymous(encrypted []byte, publicKey, privateKey *[KeyLength]byte) ([]byte, error)

OpenAnonymous authenticates and decrypts a message produced by SealAnonymous

func Precompute

func Precompute(sharedKey, peersPublicKey, privateKey *[KeyLength]byte)

Precompute calculates the shared key between peersPublicKey and privateKey and writes it to sharedKey. The shared key can be used with OpenAfterPrecomputation and SealAfterPrecomputation to speed up processing when using the same pair of keys repeatedly.

func Seal

func Seal(message []byte, peersPublicKey, privateKey *[KeyLength]byte) ([]byte, error)

Seal returns an encrypted and authenticated copy of message.

func SealAfterPrecomputation

func SealAfterPrecomputation(message []byte, sharedKey *[KeyLength]byte) ([]byte, error)

SealAfterPrecomputation performs the same actions as Seal, but takes a shared key as generated by Precompute.

func SealAnonymous

func SealAnonymous(message []byte, publicKey *[KeyLength]byte) ([]byte, error)

SealAnonymous returns an encrypted and authenticated copy of message, This differs from Seal in that the sender is not required to provide a private key.

Types

type BoxKey

type BoxKey [KeyLength]byte

func GenerateKey

func GenerateKey() (publicKey, privateKey BoxKey)

GenerateKey generates a new public/private key pair suitable for use with Seal and Open

func (BoxKey) Decrypt

func (b BoxKey) Decrypt(encrypted []byte) ([]byte, error)

Decrypt decrypts encrypted message using OpenAnonymous of nacl/box with PrivateKey and related PublicKey

func (BoxKey) Encrypt

func (b BoxKey) Encrypt(msg []byte) ([]byte, error)

Encrypt encrypts message using SealAnonymous of nacl/box with PublicKey

func (BoxKey) String

func (b BoxKey) String() string

Jump to

Keyboard shortcuts

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