Skip to content
master
Switch branches/tags
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 

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

About

Encrypt and decrypt JSON with secretbox

Resources

Releases

No releases published

Packages

No packages published

Languages