md5-hash-file
is a useful tool for
getting an md5 hash (fingerprint) from an input file using the standard
crypto/md5
package.
I also added a flag to read in your .ssh/id_rsa.pub key to get your ssh md5 fingerprint.
Table of Contents,
Documentation and references,
OVERVIEW
In a nutshell, the guts of the code is,
plainTextBytes := []byte(plainText)
// HASH
md5HashByte := md5.Sum(plainTextBytes)
// CONVERT TO STRING
md5Hash := hex.EncodeToString(md5HashByte[:])
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
md5-hash-file.go
from the command line,
go run . testfile.txt
go run md5-hash-file.go testfile.txt
go run md5-hash-file.go -debug testfile.txt
If you run on testfile.txt your md5 hash shall be,
950dc9055bc2eb9b1f143e92d7bee6c4
You may also use the -ssh flag to read in a public ssh key file,
go run . -ssh ~/.ssh/id_rsa.pub
go run md5-hash-file.go -ssh ~/.ssh/id_rsa.pub
go run md5-hash-file.go -ssh -debug ~/.ssh/id_rsa.pub
Its nice because you can check you have the right fingerprint at
github.com/settings/keys.
You can also run the unix command to check your md5,
ssh-keygen -l -E md5 -f ~/.ssh/id_rsa.pub
TEST
The following steps are located in
unit-tests.sh.
To create _test
files,
gotests -w -all md5-hash-file.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 md5-hash-file.go
USAGE
md5-hash-file {-h|-v|-debug|-ssh} [FILENAME]
-h
Help,
md5-hash-file -h
-v
Version,
md5-hash-file -v
-ssh
Check your public ssh file,
md5-hash-file -ssh ~/.ssh/id_rsa.pub
-debug
md5-hash-file -debug testfile.txt