Help us shape the future of Go! Take the 2026 Go Developer Survey

example

command
v0.1.0-rc.3 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 6 Imported by: 0

README

encrypt example

A runnable tour of the Go SDK against real ZeroKMS: declare a struct with stash tags, generate its encrypted type, seal a batch in one request, derive a query term, open the batch again, and verify a matches query over it.

Running it

stash auth login              # once; the example reads ~/.cipherstash
mise run go:encrypt:example   # builds both guests, then runs

Or, if you would rather drive it yourself:

mise run wasm:guest:build wasm:auth-guest:build
cd languages/golang && go run ./encrypt/example

The guest builds are not optional. The encrypt package embeds wasm/stack_encrypt_guest.wasm and auth embeds wasm/stack_auth_guest.wasm; both are gitignored, so a fresh checkout has no guests and NewClient fails until they are built.

What it shows

  • model.go: the struct and its go:generate line.
  • user_stash.go: what stashgen wrote from the tags. Regenerate it with go generate ./...; CI fails when that changes a committed file.
  • main.go: Encrypt, Fields.Email.Eq, Decrypt, and Fields.Email.Matches with Verify on the decrypted rows.

Documentation

Overview

Command example encrypts a batch of users against real ZeroKMS, using the credentials `stash auth login` leaves in the developer profile (or the CS_* environment variables, which win), and reads them back.

stash auth login
mise run go:encrypt:example       # builds both guests, then runs

The struct's stash tags are the declaration; user_stash.go beside this file is what `go generate` wrote from them, and the program calls only the functions in it.

Directories

Path Synopsis
Command json demonstrates a typed encrypted JSON document in PostgreSQL.
Command json demonstrates a typed encrypted JSON document in PostgreSQL.

Jump to

Keyboard shortcuts

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