enc

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package enc provides functions for encoding, compressing and encrypting data as well as managing keys.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compress

func Compress(in []byte) (out []byte, ratio float32, err error)

Compress use Zstandard compression algorithm to compress data. zstd.SpeedBestCompression is used: https://github.com/klauspost/compress/tree/master/zstd

special case: nil input == []byte{} output special case: []byte{} input == []byte{} output

func CreateKeyFile

func CreateKeyFile(path string) error

CreateKeyFile creates a new key file that contains exactly 128 random bytes. Existing files are NOT overwritten.

func CryptBytes

func CryptBytes(data []byte, offset int64, key []byte)

CryptBytes encrypts or decrypts the bytes from a chunk The specified offset refers to the entire chunk as a file.

ATTENTION: The values in data are changed by the function. In the event of an error, PANIC terminates and the data remain unchanged. This is only possible with the wrong key length.

encryption with AES-CTR (https://gchq.github.io/CyberChef/)
  The nonce is static! Therefore, each chunk MUST have its own key.
  Counter start at 0 and changes with the offset.
  There is no padding.
  [{"op":"AES Encrypt","args":[{"option":"Hex","string":"0101010101010...256 Bit PartKey...01010101010101"},
  {"option":"Hex","string":"00000000000000000000000000000000"},
  {"option":"Hex","string":""},"CTR","NoPadding","Key","Hex"]}]

func CryptoReader

func CryptoReader(r io.ReadCloser, cryptOff int64, dataKey []byte) io.ReadCloser

CryptoReader decrypts or encrypts a given reader. cryptOff is for the correct encryption position.

func Decompress

func Decompress(in []byte) (out []byte, err error)

Decompress use Zstandard compression algorithm to decompress data. https://github.com/klauspost/compress/tree/master/zstd

special case: nil input == []byte{} output special case: []byte{} input == []byte{} output

Types

type KeyFile

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

KeyFile manages the secret keys

func LoadKeyFile

func LoadKeyFile(path string) (*KeyFile, error)

LoadKeyFile read the 128 bytes key file and generate the secrets.

func (*KeyFile) CryptName

func (k *KeyFile) CryptName(plainHash []byte) string

CryptName calculates the encrypted file name of a file part. The plain text hash of the data is required for the calculation. return 64 bytes (SHA 512) as hex string

func (*KeyFile) DataKey

func (k *KeyFile) DataKey(plainHash []byte) []byte

DataKey calculates the key for data. The key is derived from the unencrypted original data (plain SHA512). return 32 bytes (AES 256 key)

func (*KeyFile) IndexKey

func (k *KeyFile) IndexKey() []byte

IndexKey calculates the key for the database (index). return 32 bytes (AES 256 key)

Jump to

Keyboard shortcuts

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