crypto

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 31, 2020 License: MIT Imports: 12 Imported by: 0

README

crypto

This library converts bytes into an encrypted binary format and back.

crypto uses the (GCM mode of operation)[https://en.wikipedia.org/wiki/Galois/Counter_Mode] with the specified block cipher to create cipher text that is then packaged in a binary file format.

Keys are derived from the given password using HMAC-SHA-256 based PBKDF2 key derivation function.

Supported Ciphers

  • AES256 (default)
  • Twofish
  • Serpent

The binary format is meant to be as efficient as possible, and thus minimally invasive

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decrypt

func Decrypt(password []byte, data []byte) ([]byte, error)

Decrypt data block with the given password, encryption type

is derived from data block metadata

func Encrypt

func Encrypt(cipherType CipherType, password []byte, data []byte) ([]byte, error)

Encrypt data with password in the given CryptType format

Types

type AES256Cipher

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

AES256Cipher encrypts using AES256-GCM

func NewAES256Cipher

func NewAES256Cipher() *AES256Cipher

NewAES256Cipher constructor

func (*AES256Cipher) Decrypt

func (c *AES256Cipher) Decrypt(data []byte, password []byte) ([]byte, error)

Decrypt data using AES256-GCM cipher. This both hides the content of the data and provides a check that it hasn't been altered. Expects input form nonce|ciphertext|tag|salt where '|' indicates concatenation.

func (*AES256Cipher) Encrypt

func (c *AES256Cipher) Encrypt(data []byte, password []byte) ([]byte, error)

Encrypt data using AES256-GCM cipher. This both hides the content of the data and provides a check that it hasn't been altered. Output takes the form nonce|ciphertext|tag|salt where '|' indicates concatenation.

func (*AES256Cipher) GetDescription

func (c *AES256Cipher) GetDescription() string

GetDescription returns description string

func (*AES256Cipher) GetName

func (c *AES256Cipher) GetName() string

GetName returns name string

func (*AES256Cipher) GetType

func (c *AES256Cipher) GetType() CipherType

GetType returns CryptType

type Cipher

type Cipher interface {
	Encrypt(data []byte, password []byte) ([]byte, error)
	Decrypt(data []byte, password []byte) ([]byte, error)
	GetDescription() string
	GetName() string
	GetType() CipherType
}

Cipher interface represents a en/decrypting module

func GetCipherList

func GetCipherList() []Cipher

GetCipherList returns a list of strings

type CipherType

type CipherType uint8

CipherType is the cipher type

const (
	Unknown CipherType = iota
	AES256
	TWOFISH
	SERPENT
)

cipher types

func GetCipherTypeByName

func GetCipherTypeByName(name string) (c CipherType, err error)

GetCipherTypeByName gets the CipherType by name

type DataIsEncryptedError

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

DataIsEncryptedError when trying to encrypt already encrypted data

func NewDataIsEcryptedError

func NewDataIsEcryptedError() *DataIsEncryptedError

NewDataIsEcryptedError returns a new error

func (*DataIsEncryptedError) Error

func (e *DataIsEncryptedError) Error() string

type DataIsNotEncryptedError

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

DataIsNotEncryptedError when trying to decrypt data that is not encrypted

func NewDataIsNotEncryptedError

func NewDataIsNotEncryptedError() *DataIsNotEncryptedError

NewDataIsNotEncryptedError returns a new error

func (*DataIsNotEncryptedError) Error

func (e *DataIsNotEncryptedError) Error() string

type SerpentCipher

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

SerpentCipher encrypts using Serpent-GCM

func NewSerpentCipher

func NewSerpentCipher() *SerpentCipher

NewSerpentCipher constructor

func (*SerpentCipher) Decrypt

func (c *SerpentCipher) Decrypt(data []byte, password []byte) ([]byte, error)

Decrypt data using Serpent-GCM cipher. This both hides the content of the data and provides a check that it hasn't been altered. Expects input form nonce|ciphertext|tag|salt where '|' indicates concatenation.

func (*SerpentCipher) Encrypt

func (c *SerpentCipher) Encrypt(data []byte, password []byte) ([]byte, error)

Encrypt data using the Serpent-GCM cipher. Output takes the form nonce|ciphertext|tag|salt where '|' indicates concatenation.

func (*SerpentCipher) GetDescription

func (c *SerpentCipher) GetDescription() string

GetDescription returns description string

func (*SerpentCipher) GetName

func (c *SerpentCipher) GetName() string

GetName returns name string

func (*SerpentCipher) GetType

func (c *SerpentCipher) GetType() CipherType

GetType returns CryptType

type TwofishCipher

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

TwofishCipher encrypts using Twofish-GCM

func NewTwofishCipher

func NewTwofishCipher() *TwofishCipher

NewTwofishCipher constructor

func (*TwofishCipher) Decrypt

func (c *TwofishCipher) Decrypt(data []byte, password []byte) ([]byte, error)

Decrypt data using Twofish-GCM cipher. This both hides the content of the data and provides a check that it hasn't been altered. Expects input form nonce|ciphertext|tag|salt where '|' indicates concatenation.

func (*TwofishCipher) Encrypt

func (c *TwofishCipher) Encrypt(data []byte, password []byte) ([]byte, error)

Encrypt data using the Twofish-GCM cipher. Output takes the form nonce|ciphertext|tag|salt where '|' indicates concatenation.

func (*TwofishCipher) GetDescription

func (c *TwofishCipher) GetDescription() string

GetDescription returns description string

func (*TwofishCipher) GetName

func (c *TwofishCipher) GetName() string

GetName returns name string

func (*TwofishCipher) GetType

func (c *TwofishCipher) GetType() CipherType

GetType returns CryptType

type UnknownCipherNameError

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

UnknownCipherNameError when cipher name is not known

func NewUnknownCipherNameError

func NewUnknownCipherNameError() *UnknownCipherNameError

NewUnknownCipherNameError returns a new error

func (*UnknownCipherNameError) Error

func (e *UnknownCipherNameError) Error() string

type UnknownCipherTypeError

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

UnknownCipherTypeError when cipher name is not known

func NewUnknownCipherTypeError

func NewUnknownCipherTypeError() *UnknownCipherTypeError

NewUnknownCipherTypeError returns a new error

func (*UnknownCipherTypeError) Error

func (e *UnknownCipherTypeError) Error() string

Jump to

Keyboard shortcuts

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