encrypt

package
v3.0.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2017 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package encrypt implements a generic interface to encrypt any stream of data. currently this package implements two types of encryption - Symmetric encryption using AES. - Asymmetric encrytion using RSA.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AsymmetricKey

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

AsymmetricKey - struct which encrypts/decrypts data using RSA public/private certificates

func NewAsymmetricKey

func NewAsymmetricKey(privData []byte, pubData []byte) (*AsymmetricKey, error)

NewAsymmetricKey - generates a crypto module able to encrypt/decrypt data using a pair for private and public key

func (*AsymmetricKey) Decrypt

func (a *AsymmetricKey) Decrypt(cipher []byte) ([]byte, error)

Decrypt data using public key

func (*AsymmetricKey) Encrypt

func (a *AsymmetricKey) Encrypt(plain []byte) ([]byte, error)

Encrypt data using public key

type CBCSecureMaterials

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

CBCSecureMaterials encrypts/decrypts data using AES CBC algorithm

func NewCBCSecureMaterials

func NewCBCSecureMaterials(key Key) (*CBCSecureMaterials, error)

NewCBCSecureMaterials builds new CBC crypter module with the specified encryption key (symmetric or asymmetric)

func (*CBCSecureMaterials) Close

func (s *CBCSecureMaterials) Close() error

Close implements closes the internal stream.

func (*CBCSecureMaterials) GetDesc

func (s *CBCSecureMaterials) GetDesc() string

GetDesc - user provided encryption material description in JSON (UTF8) format.

func (*CBCSecureMaterials) GetIV

func (s *CBCSecureMaterials) GetIV() string

GetIV - return randomly generated IV (per S3 object), base64 encoded.

func (*CBCSecureMaterials) GetKey

func (s *CBCSecureMaterials) GetKey() string

GetKey - return content encrypting key (cek) in encrypted form, base64 encoded.

func (*CBCSecureMaterials) Read

func (s *CBCSecureMaterials) Read(buf []byte) (n int, err error)

Fill buf with encrypted/decrypted data

func (*CBCSecureMaterials) SetupDecryptMode

func (s *CBCSecureMaterials) SetupDecryptMode(stream io.Reader, iv string, key string) error

SetupDecryptMode - tells CBC that we are going to decrypt data

func (*CBCSecureMaterials) SetupEncryptMode

func (s *CBCSecureMaterials) SetupEncryptMode(stream io.Reader) error

SetupEncryptMode - tells CBC that we are going to encrypt data

type Key

type Key interface {
	// Encrypt data using to the set encryption key
	Encrypt([]byte) ([]byte, error)
	// Decrypt data using to the set encryption key
	Decrypt([]byte) ([]byte, error)
}

Key - generic interface to encrypt/decrypt a key. We use it to encrypt/decrypt content key which is the key that encrypt/decrypt object data.

type Materials

type Materials interface {

	// Closes the wrapped stream properly, initiated by the caller.
	Close() error

	// Returns encrypted/decrypted data, io.Reader compatible.
	Read(b []byte) (int, error)

	// Get randomly generated IV, base64 encoded.
	GetIV() (iv string)

	// Get content encrypting key (cek) in encrypted form, base64 encoded.
	GetKey() (key string)

	// Get user provided encryption material description in
	// JSON (UTF8) format. This is not used, kept for future.
	GetDesc() (desc string)

	// Setup encrypt mode, further calls of Read() function
	// will return the encrypted form of data streamed
	// by the passed reader
	SetupEncryptMode(stream io.Reader) error

	// Setup decrypted mode, further calls of Read() function
	// will return the decrypted form of data streamed
	// by the passed reader
	SetupDecryptMode(stream io.Reader, iv string, key string) error
}

Materials - provides generic interface to encrypt any stream of data.

type SymmetricKey

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

SymmetricKey - encrypts data with a symmetric master key

func NewSymmetricKey

func NewSymmetricKey(b []byte) *SymmetricKey

NewSymmetricKey generates a new encrypt/decrypt crypto using an AES master key password

func (*SymmetricKey) Decrypt

func (s *SymmetricKey) Decrypt(cipher []byte) ([]byte, error)

Decrypt passed bytes

func (*SymmetricKey) Encrypt

func (s *SymmetricKey) Encrypt(plain []byte) ([]byte, error)

Encrypt passed bytes

Jump to

Keyboard shortcuts

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