Skip to content

Latest commit

 

History

History
51 lines (38 loc) · 1.25 KB

README.md

File metadata and controls

51 lines (38 loc) · 1.25 KB

LICENSE GoDoc

secretbox

Package secretbox provides utility wrapper of https://godoc.org/golang.org/x/crypto/nacl/secretbox

Library

GoDoc

import "github.com/haya14busa/secretbox"
// You can generate key with the following command.
// ruby -rsecurerandom -e 'puts SecureRandom.hex(32)'
const key = "0f5297b6f0114171e9de547801b1e8bb929fe1d091e63c6377a392ec1baa3d0b"
s, err := NewFromHexKey(key)
if err != nil {
  panic(err)
}
plaintext := "vim vim vim"

// Encrypt
ciphertext, _ := s.Encrypt([]byte(plaintext))

// Decrypt
b, err := s.Decrypt(ciphertext)
if err != nil {
  panic(err)
}

fmt.Printf("%s", b)
// OUTPUT: vim vim vim

CLI

go get -u github.com/haya14busa/secretbox/cmd/secretbox
$ export KEY=$(ruby -rsecurerandom -e 'puts SecureRandom.hex(32)')
$ echo 'vim or not vim, that is the question' | secretbox -key="${KEY}" > /tmp/ciphertext
$ secretbox -key="${KEY}" -d < /tmp/ciphertext
vim or not vim, that is the question