A thin wrapper around the Golang secretbox and awnumar/memguard package.
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.