cryptoutils

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2026 License: BSD-3-Clause, GPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package cryptoutils implements cryptographic primitives used by netcap for secure communication between distributed components. It wraps the NaCl box construction for authenticated public-key encryption and provides utilities for hashing and random token generation.

Index

Constants

View Source
const (
	// KeySize represents the byte length of Curve25519 keys.
	KeySize = 32
)

Curve25519 key dimensions used by NaCl box.

Variables

This section is empty.

Functions

func AsymmetricDecrypt

func AsymmetricDecrypt(sealed []byte, senderPub, recipientPriv *[KeySize]byte) ([]byte, bool)

AsymmetricDecrypt reverses AsymmetricEncrypt, verifying authenticity and recovering the original plaintext. Returns (nil, false) on failure.

func AsymmetricEncrypt

func AsymmetricEncrypt(message []byte, recipientPub, senderPriv *[KeySize]byte) ([]byte, error)

AsymmetricEncrypt secures plaintext using NaCl box (Curve25519 + XSalsa20 + Poly1305). The recipient's public key and sender's private key authenticate the message. Output format: [24-byte nonce][ciphertext with 16-byte auth tag]

func GenerateKeypair

func GenerateKeypair() (pub, priv *[KeySize]byte, err error)

GenerateKeypair produces a fresh Curve25519 key pair suitable for use with the NaCl box authenticated encryption scheme.

func MD5Data

func MD5Data(input []byte) []byte

MD5Data computes the MD5 digest of the input bytes. Note: MD5 is used here only for non-cryptographic checksums (e.g., file integrity).

func RandomString

func RandomString(n int) (string, error)

RandomString produces a URL-safe random string of exactly n characters. Uses base64url encoding of cryptographically random bytes.

Types

This section is empty.

Jump to

Keyboard shortcuts

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