encryptfile

command
v0.0.0-...-1edc04b Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2021 License: MIT Imports: 12 Imported by: 0

README

encryptfile tool

encryptfile is a useful tool for encryptfile a file with AES-256 GCM (a 32-byte hash key) using the crypto/aes package. Works with decryptfile.

Table of Contents,

Documentation and references,

OVERVIEW

The Advanced Encryption Standard, or AES, is a symmetric block cipher chosen by the U.S. government to protect classified information and is implemented in software and hardware throughout the world to encrypt sensitive data.

We're going to use AES-256 GCM encryption from the standard go crypto/aes package.

STEP 1 - CREATE A HASH KEY

First you need a 32 byte key (AES-256). Instead of typing a 32 character in, lets make it simple by turning a simple paraphrase into a key. We will use the standard go crypto/md5 package.

hasher := md5.New()
hasher.Write([]byte(paraphrase))
hash := hex.EncodeToString(hasher.Sum(nil))
STEP 2 - ENCRYPT FILE WITH 32 BYTE HASH KEY

The encryption was done using AES-256 GCM from my example aes-256-gcm.

Refer to that example for a complete description.

This illustration may help,

IMAGE - encryptfile - IMAGE

PREREQUISITES

I used the following language,

You will need the following go packages,

go install -v github.com/sirupsen/logrus

RUN

The following steps are located in run.sh.

To run encryptfile.go from the command line,

go run . -i input.txt -o encrypted.txt
go run encryptfile.go -i input.txt -o encrypted.txt
go run encryptfile.go -i input.txt -o encrypted.txt -debug
go run encryptfile.go -i input.txt -o encrypted.txt -paraphrasefile paraphrase.txt
go run encryptfile.go -i input.txt -o encrypted.txt -paraphrasefile ~/.ssh/id_rsa

Use the paraphrase test.

TEST

The following steps are located in unit-tests.sh.

To create _test files,

gotests -w -all encryptfile.go

To unit test the code,

go test -cover ./... | tee test/test_coverage.txt
cat test/test_coverage.txt

INSTALL

Will place an executable in your go bin,

go install encryptfile.go

USAGE

encryptfile {-h|-v|-debug} -i [input file] -o [output file] -paraphrasefile [file]
-h

Help,

encryptfile -h
-v

Version,

encryptfile -v
-i string, -o string

Use a specific input file and output file,

encryptfile -i input.txt -o encrypted.txt
-paraphrasefile string

Use a file as the paraphrase,

encryptfile -i input.txt -o encrypted.txt -paraphrasefile ~/.ssh/id_rsa
-debug
encryptfile -i input.txt -o encrypted.txt -debug

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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