scytale

package module
Version: v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2015 License: MIT Imports: 17 Imported by: 0

README

GoDoc

Scytale is a simple wrapper library to make use of encryption with Go fast and easy.

Most of the credits goes to the wonderful go.crypto library.

logo

Installation

Use go get to install the package:

$ go get gopkg.in/matm/scytale.v1

Tools

The bin/aesenc and bin/aeszip CLI tools allow file encryption using AES-256 operating in CBC mode, password-based encryption (PBE) and a PBKDF2 password-based key derivation function.

The former can be used to encrypt/decrypt a single file:

$ go install gopkg.in/matm/scytale.v1/bin/aesenc
$ aesenc -o out.enc myfile.pdf
$ aesenc -o myfile.pdf -d out.enc

The latter encrypts a bunch of files into a standard ZIP file:

$ go install gopkg.in/matm/scytale.v1/bin/aeszip
$ aeszip -o secure.zip *.pdf

Both aeszip -l and unzip -l can be used to list the content of the archive. All files within the archive can be decrypted and extracted with

$ aeszip -x -o . secure.zip

The second file in the archive (position 1) can be decrypted and extracted with

$ aeszip -x -o . -n 1 secure.zip

See aeszip -h output for usage.

API Docs

The API doc is available on GoDoc.

License

This is free software, see LICENSE.

Documentation

Index

Constants

View Source
const (
	Version = "1.2.2"
)

Variables

This section is empty.

Functions

func PKCS7Padding

func PKCS7Padding(clearTextLen, blockSize int) []byte

PKCS#7 data padding

func ReadPassword

func ReadPassword(minLen int, twice bool) (string, error)

ReadPassword reads a password of minLen lenght on the CLI and returns it. If twice is true, asks for confirmation. An error is returned if the password is empty or passwords don't match, of length of password is lesser than minLen.

Types

type AES

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

Advanced Encryption Standard

func NewAES

func NewAES(password string) (*AES, error)

Strong AES encryption, with a cipher operating in CBC mode, using a derived 256 bits key using PBKDF2.

func (*AES) Decrypt

func (a *AES) Decrypt(ciphertext []byte) []byte

Decrypt decripts a block of ciphertext. You have to ensure this ciphertext is a multiple of AES's block size.

func (*AES) DecryptFile

func (a *AES) DecryptFile(r io.Reader, w io.Writer) error

DecryptFile decrypts infile and saves the resulting AES decoding to outfile.

func (*AES) Encrypt

func (a *AES) Encrypt(plaintext []byte) []byte

func (*AES) EncryptFile

func (a *AES) EncryptFile(r io.Reader, w io.Writer) error

EncryptFile encrypts infile and saves the resulting AES encoding to outfile.

func (*AES) EncryptedFileLength

func (a *AES) EncryptedFileLength(fi os.FileInfo) int64

EncryptedFileLength returns the expected encrypted file length. This information can be used to provide file size info to archive/tar for example.

func (*AES) InitDecryption

func (a *AES) InitDecryption(iv []byte)

Uses IV and set cipher's operation mode to CBC.

func (*AES) InitEncryption

func (a *AES) InitEncryption() ([]byte, error)

Computes a random IV and set cipher's operation mode to CBC.

func (*AES) RemovePadding

func (a *AES) RemovePadding(clear []byte) []byte

RemovePadding removes extra padding for plain text.

type Cipher

type Cipher interface {
	Encrypt(key, clear []byte) []byte
	Decrypt(key, cipher []byte) []byte
}

func NewVigenere

func NewVigenere() Cipher

Vigenere's cipher implementation.

func NewXor

func NewXor() Cipher

Basic XOR cipher implementation.

type Status

type Status int
const (
	Running Status = iota
	Idle
)

type TarArchive

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

func NewTarArchive

func NewTarArchive(password string) *TarArchive

func (*TarArchive) Create

func (a *TarArchive) Create(output string, files []string) error

func (*TarArchive) Extract

func (a *TarArchive) Extract(input, outputDir string) error

type Vigenere

type Vigenere int

func (*Vigenere) Decrypt

func (v *Vigenere) Decrypt(key, cipher []byte) []byte

func (*Vigenere) Encrypt

func (v *Vigenere) Encrypt(key, clear []byte) []byte

type WalkFunc

type WalkFunc func(path string, info os.FileInfo, current, total int) error

WalkFunc is the type of the function called for each file added to the archive.

type Xor

type Xor int

func (*Xor) Decrypt

func (x *Xor) Decrypt(key, cipher []byte) []byte

func (*Xor) Encrypt

func (x *Xor) Encrypt(key, clear []byte) []byte

type ZipArchive

type ZipArchive struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewZipArchive

func NewZipArchive(password string) *ZipArchive

func (*ZipArchive) Cancel

func (a *ZipArchive) Cancel()

Cancel stops the current processing, if any.

func (*ZipArchive) Create

func (a *ZipArchive) Create(output string, files []string, fn WalkFunc, random bool) error

Create creates a new ZIP output archive given a list of input files. fn() is called just after a file has been encrypted and added to the archive. Set random to true to rename file with their md5 checksum.

func (*ZipArchive) ExtractAll

func (a *ZipArchive) ExtractAll(archive, outputDir string) error

ExtractAll extracts all encrypted files from zip archive. The resulting files are decrypted using the provided password.

func (*ZipArchive) ExtractAt

func (a *ZipArchive) ExtractAt(pos int, archive, outputDir string) error

ExtractAt extracts a single file at position pos from zip archive. The resulting file is decrypted using the provided password.

func (*ZipArchive) SetPassword

func (a *ZipArchive) SetPassword(pwd string)

func (*ZipArchive) Status

func (a *ZipArchive) Status() Status

Directories

Path Synopsis
bin

Jump to

Keyboard shortcuts

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