Skip to content

zemirco/jsonbox

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages