Categorygithub.com/aaronland/go-secretbox
repositorypackage
1.0.0
Repository: https://github.com/aaronland/go-secretbox.git
Documentation: pkg.go.dev

# 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