Encrypt and decrypt JSON with secretbox
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.travis.yml
README.md
jsonbox.go
jsonbox_test.go

README.md

jsonbox

Build Status Coverage Status GoDoc

Encrypt and decrypt JSON with secretbox.

Example

package main

import (
  "encoding/json"

  "github.com/zemirco/jsonbox"
)

type Person struct {
	Name string `json:"name"`
  // use jsonbox.Secret as type (string is underlying type)
	Code jsonbox.Secret `json:"code"`
}

func main() {
  // use your own key of length 32 in production
  rand.Reader.Read(jsonbox.Key[:])
  // create new instance
  john := Person{
    Name: "john",
    Code: "open sesame",
  }
  res, err := json.Marshal(john)
  if err != nil {
    panic(err)
  }
  // make sure code field is encrypted
  log.Println(string(res))

  // unmarshal json into new struct
  steve := Person{}
  err = json.Unmarshal(res, &steve)
  if err != nil {
    panic(err)
  }
  log.Printf("%+v", steve)
}

Test

go test

License

MIT