secretbox

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2025 License: BSD-3-Clause Imports: 7 Imported by: 4 modules, 4 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

go-secretbox

A thin wrapper around the Golang secretbox and awnumar/memguard package.

Documentation

Go Reference

Example

package main

import (
	"github.com/aaronland/go-secretbox"
	"github.com/awnumar/memguard"	
	"log"
)

func main() {

	secret := "s33kret"
	salt := "s4lty"
	plain := "hello world"

	secret_buf := memguard.NewBufferFromBytes([]byte(secret))
	defer secret_buf.Destroy()
	
	opts := secretbox.NewSecretboxOptions()
	opts.Salt = salt

	sb, _ := secretbox.NewSecretboxWithBuffer(secret_buf, opts)

	locked, _ := sb.Lock([]byte(plain))
	unlocked, _ := sb.Unlock(locked)

	if string(unlocked.String()) != plain {
		log.Fatal("Unlock failed")
	}
}

Error handling omitted for the sake of brevity.

See also

Documentation

Overview

package secretbox is a thin wrapper around the Golang secretbox(https://godoc.org/golang.org/x/crypto/nacl/secretbox) and awnumar/memguard(https://github.com/awnumar/memguard) packages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Secretbox

type Secretbox struct {
	// contains filtered or unexported fields
}

type Secretbox is that struct used to encypt and decrypt values.

func NewSecretbox

func NewSecretbox(pswd string, opts *SecretboxOptions) (*Secretbox, error)

NewSecretbox returns a new `Secretbox` instance for 'pswd' and 'opts'.

func NewSecretboxWithBuffer added in v0.3.0

func NewSecretboxWithBuffer(buf *memguard.LockedBuffer, opts *SecretboxOptions) (*Secretbox, error)

NewSecretboxWithBuffer returns a new `Secretbox` instance for 'buf' and 'opts.

func NewSecretboxWithEnclave added in v0.3.0

func NewSecretboxWithEnclave(enclave *memguard.Enclave, opts *SecretboxOptions) (*Secretbox, error)

NewSecretboxWithEnclave returns a new `Secretbox` instance for 'enclave' and 'opts.

func (Secretbox) Lock

func (sb Secretbox) Lock(body []byte) (string, error)

Lock encypts the value of 'body' and returns a base64-encoded string.

func (Secretbox) LockWithBuffer added in v0.3.0

func (sb Secretbox) LockWithBuffer(buf *memguard.LockedBuffer) (string, error)

Lock encypts the contents of 'buf' and returns a base64-encoded string.

func (Secretbox) LockWithReader added in v0.3.0

func (sb Secretbox) LockWithReader(r io.Reader) (string, error)

Lock encypts the contents of 'r' and returns a base64-encoded string.

func (Secretbox) Unlock

func (sb Secretbox) Unlock(body_hex string) (*memguard.LockedBuffer, error)

Unlock decrypts the value of 'body_hex' with is assumed to be a base64-encoded string.

type SecretboxOptions

type SecretboxOptions struct {
	// Salt is a string used to "salt" keys
	Salt string
}

SecretboxOptions is a struct with options for a specific `Secretbox` instance.

func NewSecretboxOptions

func NewSecretboxOptions() *SecretboxOptions

NewSecretboxOptions returns a `SecretboxOptions` with an empty salt.

Jump to

Keyboard shortcuts

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