secretbox

package module
v0.0.0-...-07c7ecf Latest Latest
Warning

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

Go to latest
Published: May 25, 2018 License: MIT Imports: 6 Imported by: 9

README

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

Documentation

Overview

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

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decrypt

func Decrypt(ciphertext []byte, key [32]byte) ([]byte, error)

func Encrypt

func Encrypt(plaintext []byte, key [32]byte) ([]byte, error)
Example
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

Types

type SecretBox

type SecretBox struct {
	// contains filtered or unexported fields
}

func New

func New(key [32]byte) *SecretBox

func NewFromHexKey

func NewFromHexKey(key string) (*SecretBox, error)

func (*SecretBox) Decrypt

func (s *SecretBox) Decrypt(ciphertext []byte) ([]byte, error)

func (*SecretBox) Encrypt

func (s *SecretBox) Encrypt(plaintext []byte) ([]byte, error)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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