πΎ Archived View for source.community βΊ jeffdecola βΊ my-go-tools βΊ tree βΊ develop βΊ cryptography-toolβ¦ captured on 2023-09-08 at 16:21:52. Gemini links have been rewritten to link to archived content
β¬ οΈ Previous capture (2023-07-10)
β‘οΈ Next capture (2024-02-05)
-=-=-=-=-=-=-
. ,-. ,-. . . ,-. ,-. ,-. ,-. ,-. ,-,-. ,-,-. . . ,-. . |- . . `-. | | | | | | |-' | | | | | | | | | | | | | | | | | `-' `-' `-^ ' `-' `-' :: `-' `-' ' ' ' ' ' ' `-^ ' ' ' `' `-| /| `-'
git clone https://source.community/jeffdecola/my-go-tools.git
`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[1]._
Table of Contents,
- OVERVIEW[1]
- STEP 1 - CREATE A HASH KEY[1]
- STEP 2 - ENCRYPT FILE WITH 32 BYTE HASH KEY[2]
- PREREQUISITES[3]
- RUN[4]
- TEST[5]
- INSTALL[6]
- USAGE[7]
- -h[8]
- -v[9]
- -i string, -o string[10]
- -paraphrasefile string[11]
- -debug[12]
2: STEP 2 - ENCRYPT FILE WITH 32 BYTE HASH KEY
Documentation and references,
- Use my other tool
decryptfile[1] to decrypt * Refer to my aes-256-gcm[2] example in `my-go-examples` repo on how I did the decryption.
- This repos
github webpage[1] _built with concourse[2]_
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[1] package.
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[1] package.
hasher := md5.New() hasher.Write([]byte(paraphrase)) hash := hex.EncodeToString(hasher.Sum(nil))
The encryption was done using AES-256 GCM from my example aes-256-gcm[1].
Refer to that example for a complete description.
This illustration may help,
IMAGE - encryptfile - IMAGE[1]
1: IMAGE - encryptfile - IMAGE
I used the following language,
- go[1]
You will need the following go packages,
go install -v github.com/sirupsen/logrus
The following steps are located in run.sh[1].
To run encryptfile.go[1] 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`.
The following steps are located in unit-tests.sh[1].
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
Will place an executable in your go bin,
go install encryptfile.go
encryptfile {-h|-v|-debug} -i [input file] -o [output file] -paraphrasefile [file]
Help,
encryptfile -h
Version,
encryptfile -v
Use a specific input file and output file,
encryptfile -i input.txt -o encrypted.txt
Use a file as the paraphrase,
encryptfile -i input.txt -o encrypted.txt -paraphrasefile ~/.ssh/id_rsa
encryptfile -i input.txt -o encrypted.txt -debug
Β· Β· Β·
Β© 2023 source.community