secret

package module
v0.0.0-...-77dcc7d Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2019 License: MIT Imports: 9 Imported by: 0

README

go-secret

Build Status GoDoc

Symmetrically encrypt and decrypt with passphrase using OpenPGP

SYNOPSIS

func ExampleEncrypt() {
	// a config including sensitive data
	type Config struct {
		ID       string
		Password string
	}
	cfg := Config{
		ID:       "somethingID",
		Password: "somethingPassword",
	}
	masterPassword := "qwerty"

	var buf bytes.Buffer
	// you can use Encrypter like json.Encoder
	if err := secret.NewEncrypter(&buf).Encrypt(cfg, masterPassword); err != nil {
		log.Fatal(err)
	}
	// now buf contains encrypted data
}

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decrypt

func Decrypt(data []byte, v interface{}, passphrase string) error

Decrypt given data as encrypted with passphrase, and stores decrypted result into v.

func Encrypt

func Encrypt(v interface{}, passphrase string) ([]byte, error)

Encrypt retruns the encrypted byte array of v. Before encrypting, Encrypt serializes v as json

Example
package main

import (
	"bytes"
	"log"

	secret "github.com/nasa9084/go-secret"
)

func main() {
	// a config including sensitive data
	type Config struct {
		ID       string
		Password string
	}
	cfg := Config{
		ID:       "somethingID",
		Password: "somethingPassword",
	}
	masterPassword := "qwerty"

	var buf bytes.Buffer
	// you can use Encrypter like json.Encoder
	if err := secret.NewEncrypter(&buf).Encrypt(cfg, masterPassword); err != nil {
		log.Fatal(err)
	}
	// now buf contains encrypted data
}
Output:

Types

type Decrypter

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

Decrypter reads and decrypt from an input stream.

func NewDecrypter

func NewDecrypter(r io.Reader) *Decrypter

NewDecrypter returns a new decrypter that reads from r.

func (*Decrypter) Decrypt

func (dec *Decrypter) Decrypt(v interface{}, passphrase string) error

Decrypt encrypted value with passphrase and stores decrypted result into v.

type Encrypter

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

An Encrypter writes encrypted values to an output stream.

func NewEncrypter

func NewEncrypter(w io.Writer) *Encrypter

NewEncrypter returns a new encrypter that writes to w.

func (*Encrypter) Encrypt

func (enc *Encrypter) Encrypt(v interface{}, passphrase string) error

Encrypt writes the encrypted value of v to the stream. Before encrypting, Encrypt serializes v as json.

Jump to

Keyboard shortcuts

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