decryptfile
is a useful tool for
decryptfile a file with AES-256 GCM (a 32-byte hash key) using the crypto/aes
package.
Works with
encryptfile.
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 - DECRYPT 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,
PREREQUISITES
I used the following language,
You will need the following go packages,
go get -u -v github.com/sirupsen/logrus
RUN
The following steps are located in
run.sh.
To run
decryptfile.go
from the command line,
go run . -i encrypted.txt -o output.txt
go run decryptfile.go -i encrypted.txt -o output.txt
go run decryptfile.go -i encrypted.txt -o output.txt -debug
go run decryptfile.go -i encrypted.txt -o output.txt -paraphrasefile paraphrase.txt
go run decryptfile.go -i encrypted.txt -o output.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 decryptfile.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 decryptfile.go
USAGE
decryptfile {-h|-v|-debug} -i [input file] -o [output file] -paraphrasefile [file]
-h
Help,
decryptfile -h
-v
Version,
decryptfile -v
-i string, -o string
Use a specific input file and output file`,
decryptfile -i encrypted.txt -o output.txt
-paraphrasefile string
Use a file as the paraphrase,
decryptfile -i encrypted.txt -o output.txt -paraphrasefile ~/.ssh/id_rsa
-debug
decryptfile -i encrypted.txt -o output.txt -debug