xcmd_cryptpng

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2020 License: Apache-2.0 Imports: 19 Imported by: 0

README

Cryptpng

A way to store encrypted data inside a png without altering the image itself.

Usage

# encrypt
cryptpng encrypt --image <name of the image> --in <input file> --out <output file>

# decrypt
cryptpng decrypt --image <crypt image> --out <decrypted output file>

Technical Information

It should be possible to store data with a size up to ~ 4GB, but in reality most image viewers have problems with chunks that are bigger than several Megabytes. The data itself is stored in a png chunk and encrypted via aes. The encryption chunk is stored right before the IDAT chunk that contains the image data. The steps for encrypting are:

Encrypt
  1. Parse the png file and split it into chunks.
  2. Prompt for a password and use the scrypt 32byte value with a generated salt.
  3. Store the salt in the saLt chunk.
  4. Encrypt the data using aes and the provided hashed key.
  5. Split the data into parts of 1 MiB of size.
  6. Store every data part into a separate crPt chunk.
  7. Write the png header and chunks to the output file.
Decrypt
  1. Parse the png file and split it into chunks.
  2. Get the saLt chunk.
  3. Get the crPt chunks and and concat the data.
  4. Prompt for the password and create the scrypt 32byte hash with the salt.
  5. Decrypt the data using aes and the provided hash key.
  6. Write the data to the specified output file.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecryptDataPng

func DecryptDataPng(f *os.File, fout *os.File)

Decrypts the data from a png file

func EncryptDataPng

func EncryptDataPng(f *os.File, fin *os.File, fout *os.File)

encrypts the data of fin inside the png (f) and writes it to fout

func ValidatePng

func ValidatePng(f *os.File) (bool, []byte)

validates the png by reading the header of the file

Types

type ChunkData

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

func CreateChunk

func CreateChunk(data []byte, name string) ChunkData

creates a chunk with the given data and name

func ReadChunk

func ReadChunk(f *os.File) (ChunkData, error)

reads the data of one chunk it is assumed that the file reader is at the beginning of the chunk when reading

func (*ChunkData) GetRaw

func (c *ChunkData) GetRaw() []byte

func (*ChunkData) Verify

func (c *ChunkData) Verify() bool

verifies the integrity of the chunks data using crc

type PngData

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

func (*PngData) AddMetaChunk

func (p *PngData) AddMetaChunk(metaChunk ChunkData)

adds a meta chunk to the chunk data before the IDAT chunk.

func (*PngData) GetChunk

func (p *PngData) GetChunk(name string) *ChunkData

Returns the reference of a chunk by name

func (*PngData) GetChunksByName

func (p *PngData) GetChunksByName(name string) []ChunkData

returns all chunks with a given name

func (*PngData) Read

func (p *PngData) Read(f *os.File) error

Reads the png data from a file into the struct

func (*PngData) Write

func (p *PngData) Write(f *os.File) error

writes all the data of the png into a new file

Jump to

Keyboard shortcuts

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