shredder

package module
v0.0.0-...-b2488ae Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2018 License: Apache-2.0 Imports: 13 Imported by: 3

README

Go-Shredder

Go-Shredder is a package which helps you to split a file, or a byte array into chunks. You wan also encrypt the content with GnuPG or AES encryption.

GoDoc Build Status Go Report Card

Sample usages

Shred a file, reassemble the chunks and print the file content.

    chunks, err := ShredFile("main.go", &Opts{
        ChunkSize: 100,
    })
    if err != nil {
        panic(err)
    }

    content, err := Reassemble(chunks, &Opts{
        ChunkSize: 100,
    })
    if err != nil {
        panic(err)
    }

    fmt.Println(content.String())

With Gnu-PG encryption

Shred a file with GPG encryption. You just need the public key to encrypt.

    chunks, err := ShredFile("main.go", &Opts{
        GPGEncryption: &GPGEncryption{
                PublicKey:  []byte(publicKey),
            },
        ChunkSize: 100,
    })
    if err != nil {
        panic(err)
    }

Reassemble the file; so you need private key and the passphrase.

    content, err := Reassemble(chunks, &Opts{
        GPGEncryption: &GPGEncryption{
            PrivateKey: []byte(privateKey),
            Passphrase: []byte("password"),
        },
        ChunkSize: 100,
    })
    if err != nil {
        panic(err)
    }
    fmt.Println(content.String())

With AES encryption

Shred a file with AES encryption.

    chunks, err := ShredFile("main.go", &Opts{
        AESEncryption:  &AESEncryption{
            key: []byte("a very very very very secret key"), //32 bytes long key
        },
        ChunkSize: 100,
    })
    if err != nil {
        panic(err)
    }

Reassemble the file

    content, err := Reassemble(chunks, &Opts{
        AESEncryption:  &AESEncryption{
            key: []byte("a very very very very secret key"), //32 bytes long key
        },
        ChunkSize: 100,
    })
    if err != nil {
        panic(err)
    }
    fmt.Println(content.String())

Documentation

Index

Constants

View Source
const (
	BytesContentType = "bytes"
	FileContentType  = "file"
)

Variables

This section is empty.

Functions

func AESDecrypt

func AESDecrypt(key []byte, content io.Reader) (io.Reader, error)

func AESEncrypt

func AESEncrypt(key []byte, content io.Reader) (io.Reader, error)

func Filter

func Filter(chunks Chunks) map[string]Chunks

Filter filters a list of chunks and returns a map of chunks according to their context ID.

func GPGDecrypt

func GPGDecrypt(privateKey, passphrase []byte, content io.Reader) (io.Reader, error)

func GPGEncrypt

func GPGEncrypt(publicKey []byte, content io.Reader) (io.Reader, error)

Types

type AESEncryption

type AESEncryption struct {
	Key []byte
}

AESEncryption use https://golang.org/pkg/crypto/aes/ for file content encryption/decryption

type Chunk

type Chunk struct {
	Ctx    *Ctx
	Data   []byte
	Offset int
}

Chunk is a piece of schredded file

type Chunks

type Chunks []Chunk

Chunks is an array of chunks

func Shred

func Shred(content []byte, id string, opts *Opts) (Chunks, error)

Shred shreds a byte array into a an array of chunks according to options. You can pass nil as option, chunks size will be 512 bytes. You can define Encryption option such as GPG or AES. See GPGEncryption and AESEncryption structures.

func ShredFile

func ShredFile(filename string, id string, opts *Opts) (Chunks, error)

ShredFile shreds a file content. See Shred for more details

func (Chunks) Completed

func (s Chunks) Completed() bool

Completed returns true when chunks is made of all needed chunks

func (Chunks) Context

func (s Chunks) Context() *Ctx

Context returns the context

func (*Chunks) Delete

func (s *Chunks) Delete(c Chunk)

Delete removes a chunks from a chunks list

func (Chunks) Len

func (s Chunks) Len() int

func (Chunks) Less

func (s Chunks) Less(i, j int) bool

func (Chunks) Swap

func (s Chunks) Swap(i, j int)

type Ctx

type Ctx struct {
	UUID        string
	ContentType string

	Opts         *Opts
	ChunksNumber int
	// contains filtered or unexported fields
}

Ctx is a context for a shredding

func Reassemble

func Reassemble(s Chunks, opts *Opts) (*Ctx, error)

Reassemble computes a list of chunks, eventually decrypt the content (according to options)

func (*Ctx) Bytes

func (ctx *Ctx) Bytes() []byte

Bytes returns the content as a byte array

func (*Ctx) File

func (ctx *Ctx) File() (string, []byte, error)

File returns the filename and one content according to the context content type. If the context content type is not a file, an error will be returned

func (*Ctx) GetUUID

func (ctx *Ctx) GetUUID() string

func (*Ctx) String

func (ctx *Ctx) String() string

Bytes returns the content as a string

type GPGEncryption

type GPGEncryption struct {
	PrivateKey []byte
	Passphrase []byte
	PublicKey  []byte
}

GPGEncryption use GPG to file content encryption/decryption

type Opts

type Opts struct {
	AESEncryption *AESEncryption
	GPGEncryption *GPGEncryption
	ChunkSize     int64
}

Opts is here to set option on shredder like Encryption of chunksize

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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