crypto

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2018 License: Apache-2.0 Imports: 16 Imported by: 4

Documentation

Index

Constants

View Source
const (
	// BaseCryptoURL is the base url to append query params to in compat mode
	BaseCryptoURL = "https://crypto.senetas.com/"

	// AlgosKey is the key used for the algos field in the url encoding of the crypto object
	AlgosKey = "algos"

	// VersionKey is the key used for the version field in the url encoding of the crypto object
	VersionKey = "version"

	// KeyKey is the key used for the (encrypted) data key in the url encoding of the crypto object
	KeyKey = "key"

	// NonceKey is the key used for the version field in the url encoding of the crypto object
	NonceKey = "nonce"

	// SaltKey is the key used for the version field in the url encoding of the crypto object
	SaltKey = "salt"

	// ItersKey is the key used for the version field in the url encoding of the crypto object
	ItersKey = "iters"
)

Variables

View Source
var StdinPassReader = func() ([]byte, error) { return terminal.ReadPassword(syscall.Stdin) }

StdinPassReader reads a password from stdin

Functions

func DecBlobReader

func DecBlobReader(in io.Reader, key []byte) (io.Reader, error)

DecBlobReader returns an io.Reader that decrypts read data with the supplied key

func DecryptJSON

func DecryptJSON(ciphertext string, key, nonce, salt []byte, val interface{}) (err error)

DecryptJSON decrypts a string that is the base64 (URL) encoded ciphertext of a json object and assigns that object to val

func EncBlobWriter

func EncBlobWriter(in io.Writer, key []byte) (io.WriteCloser, error)

EncBlobWriter returns an io.WriteCloser that encrypts written data with the supplied key

func EncryptJSON

func EncryptJSON(val interface{}, key, nonce, salt []byte) (ciphertext string, err error)

EncryptJSON encrypts a JSON object and base64 (URL) encodes the ciphertext

func GetPassSTDIN

func GetPassSTDIN(prompt string, passReader func() ([]byte, error)) (_ string, err error)

GetPassSTDIN prompte the user for a passphrase

func NewURLCompat

func NewURLCompat(e *EnCrypto, opts *Opts) (u *url.URL, err error)

NewURLCompat creates a url from an EnCrypto struct

Types

type Algos

type Algos string

Algos represents the collection of algorithms used for encryption and authentication

const (
	// None represents an identity encryption function
	None Algos = "NONE"

	// Pbkdf2Aes256Gcm represents aead with AES256-GCM with a key derived
	// from a passphrase using PBKDF2
	Pbkdf2Aes256Gcm Algos = "PBKDF2-AES256-GCM"

	// Pbkdf2Iter is the number of iterations of PBKDF2 to run
	Pbkdf2Iter = 4e4
)

func ValidateAlgos

func ValidateAlgos(ctstr string) (Algos, error)

ValidateAlgos converts a string to valid Algos if possible

type Crypto

type Crypto struct {
	Algos   Algos  `json:"algos"`
	Nonce   []byte `json:"nonce"`
	Salt    []byte `json:"salt"`
	Iters   int    `json:"iters"`
	Version int    `json:"version"`
}

Crypto contains the common parts of EnCrypto and DeCrypto

type DeCrypto

type DeCrypto struct {
	Crypto
	DecKey []byte `json:"-"`
}

DeCrypto is a decrypted key with the algotithms used to encrypt it and the data

func DecryptKey

func DecryptKey(e EnCrypto, opts *Opts) (d DeCrypto, err error)

DecryptKey is the inverse function of EncryptKey (up to error)

func NewDecrypto

func NewDecrypto(opts *Opts) (d *DeCrypto, err error)

NewDecrypto create a new DeCrypto struct that holds decrupted key data

type EnCrypto

type EnCrypto struct {
	Crypto
	EncKey []byte `json:"key"`
}

EnCrypto is a encrypted key with the algotithms used to encrypt it and the data

func EncryptKey

func EncryptKey(d DeCrypto, opts *Opts) (e EnCrypto, err error)

EncryptKey encrypts a plaintext key with a passphrase and salt

func NewEncryptoCompat

func NewEncryptoCompat(urls []string, opts *Opts) (e EnCrypto, err error)

NewEncryptoCompat create a new Encrypto struct from some URLs

type Opts

type Opts struct {
	// whether the encryption data should be stored in a v2.2 compatible manifest or not
	Compat bool

	Version int
	Algos   Algos
	Iter    int
	// contains filtered or unexported fields
}

Opts stores data necessary for encryption

func (*Opts) GetPassphrase

func (o *Opts) GetPassphrase(passReader func() ([]byte, error)) (_ string, err error)

GetPassphrase prompt the user to enter a passphrase to decrypt

func (*Opts) SetPassphrase

func (o *Opts) SetPassphrase(passphrase string)

SetPassphrase sets the passphrase

Jump to

Keyboard shortcuts

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