protectedblob

package module
v0.0.0-...-890b1ca Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2015 License: MIT Imports: 10 Imported by: 0

README

protectedblob

Build Status

Package protectedblob can create passphrase-protected wrappers for binary blobs (any non-empty arbitary byte arrays).

The wrapper, called an envelop, uses a randomly-generated key to encrypt the given byte array. The key is then encrypted with another key that's derived from user-supplied passphrase. The integrity of the encrypted blob is checked with an HMAC (hash-based message authentication code). The HMAC is computed with the encrypted data and another key derived from the passphrase. Together, this implements an encrypt-then-MAC authenticated encryption scheme.

package main

import "github.com/lukhnos/protectedblob-go"

func someFunc() {
    envelope, _ := protectedblob.Create(plaintext, passphrase, rounds)
    jsonBytes, _ := envelope.ToJSON()
    // Write out the JSON.

    envelope, _ := protectedblob.FromJSON(jsonBytes)
    plaintext, _ := envelope.GetPlaintext(passphrase)
}

A command line tool under the same name is also provided to create and use the envelopes. To install the command line tool:

go get github.com/lukhnos/protectedblob-go
go install github.com/lukhnos/protectedblob-go/...

This is a Go port of protectedblob-py.

Documentation

Overview

Package protectedblob can create passphrase-protected wrappers for binary blobs (any non-empty arbitary byte arrays).

The wrapper, called an envelop, uses a randomly-generated key to encrypt the given byte array. The key is then encrypted with another key that's derived from user-supplied passphrase. The integrity of the encrypted blob is checked with an HMAC (hash-based message authentication code). The HMAC is computed with the encrypted data and another key derived from the passphrase. Together, this implements an encrypt-then-MAC authenticated encryption scheme.

package main

import "github.com/lukhnos/protectedblob-go"

func someFunc() {
    envelope, _ := protectedblob.Create(plaintext, passphrase, rounds)
    jsonBytes, _ := envelope.ToJSON()
    // Write out the JSON.

    envelope, _ := protectedblob.FromJSON(jsonBytes)
    plaintext, _ := envelope.GetPlaintext(passphrase)
}

A command line tool under the same name is also provided to create and use the envelopes. To install the command line tool:

go get github.com/lukhnos/protectedblob-go
go install github.com/lukhnos/protectedblob-go/...

This is a Go port of protectedblob-py (https://github.com/lukhnos/protectedblob-py).

Index

Constants

View Source
const DefaultRounds int32 = 131072
View Source
const SupportedVersion string = "2"

Variables

View Source
var AES256CBCSHA256 = _AES256CBCSHA256{}
View Source
var PBKDF2SHA256AES256 = _PBKDF2SHA256AES256{}

Functions

This section is empty.

Types

type BlobError

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

func (*BlobError) Error

func (e *BlobError) Error() string

type CipherSuite

type CipherSuite interface {
	Name() string
	Validate(src Data) error
	GenerateKey() ([]byte, error)

	Decrypt(key []byte, data Data) ([]byte, error)
	Encrypt(key, plaintext []byte) (Data, error)
	// contains filtered or unexported methods
}

type Data

type Data struct {
	IV         []byte `json:"iv"`
	Ciphertext []byte `json:"ciphertext"`
	HMAC       []byte `json:"hmac"`
}

type DerivedKeyPair

type DerivedKeyPair struct {
	CipherKey []byte
	HMACKey   []byte
}

type Envelope

type Envelope struct {
	Version      string       `json:"version"`
	CipherSuite  string       `json:"cipher_suite"`
	KDF          string       `json:"kdf"`
	Data         Data         `json:"encrypted_data"`
	ProtectedKey ProtectedKey `json:"encrypted_key"`
}

func Create

func Create(plaintext []byte, passphrase string, rounds int32) (Envelope, error)

func FromJSON

func FromJSON(data []byte) (Envelope, error)

func (*Envelope) ChangePassphrase

func (envlp *Envelope) ChangePassphrase(oldPhrase string, newPhrase string) error

func (*Envelope) ChangePassphraseAndRounds

func (envlp *Envelope) ChangePassphraseAndRounds(oldPhrase string, newPhrase string, newRounds int32) error

func (*Envelope) GetPlaintext

func (envlp *Envelope) GetPlaintext(passphrase string) ([]byte, error)

func (*Envelope) ToJSON

func (envlp *Envelope) ToJSON() ([]byte, error)

type KDF

type KDF interface {
	Name() string
	Validate(src ProtectedKey) error
	Encrypt(key []byte, passphrase string, rounds int32) (ProtectedKey, error)
	Decrypt(src ProtectedKey, passphrase string) ([]byte, error)
}

type ProtectedKey

type ProtectedKey struct {
	Salt         []byte `json:"salt"`
	Rounds       int32  `json:"rounds"`
	EncryptedKey []byte `json:"encrypted_key"`
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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