Documentation
¶
Overview ¶
Package enc provides functions for encoding, compressing and encrypting data as well as managing keys.
Index ¶
- func Compress(in []byte) (out []byte, ratio float32, err error)
- func CreateKeyFile(path string) error
- func CryptBytes(data []byte, offset int64, key []byte)
- func CryptoReader(r io.ReadCloser, cryptOff int64, dataKey []byte) io.ReadCloser
- func Decompress(in []byte) (out []byte, err error)
- type KeyFile
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Compress ¶
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 ¶
CreateKeyFile creates a new key file that contains exactly 128 random bytes. Existing files are NOT overwritten.
func CryptBytes ¶
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 ¶
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 ¶
LoadKeyFile read the 128 bytes key file and generate the secrets.
func (*KeyFile) CryptName ¶
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