You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

github.com/JeffDeCola/my-go-tools/cryptography-tools/sha256-hash-file

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/JeffDeCola/my-go-tools/cryptography-tools/sha256-hash-file

v0.0.0-20250116100801-dde3a3808884
Source
Go
Version published
Created
Source

sha256-hash-file TOOL

Get an sha256 hash (fingerprint) from an input file using the standard crypto/sha256 package. I also added a flag to read in your .ssh/id_rsa.pub key to get your ssh fingerprint.

tl;dr,

# INSTALL VIA GO
go install sh256-hash-file.go

# GET SH256 FINGERPRINT ON FILE
sha256-hash-file testfile.txt

# GET SH256 FINGERPRINT ON KEY FILE
sha256-hash-file -ssh ~/.ssh/id_rsa.pub

Table of Contents

  • OVERVIEW
  • PREREQUISITES
  • RUN
  • TEST
  • INSTALL
  • USAGE

Documentation and Reference

OVERVIEW

In a nutshell, the guts of the code is,

plainTextBytes := []byte(plainText)

// HASH
sha256HashByte := sha256.Sum256(plainTextBytes)

// CONVERT TO STRING
sha256Hash := base64.RawStdEncoding.EncodeToString(sha256HashByte[:])

PREREQUISITES

You will need the following go packages,

go get -u -v github.com/sirupsen/logrus

RUN

To run.sh,

go run . testfile.txt
go run sha256-hash-file.go testfile.txt
go run sha256-hash-file.go testfile.txt -loglevel trace

If you run on testfile.txt your sha256 hash shall be,

r2pN5Sjq43jggvxvW34cT6s662//HfyemRss38ZA+vk

You may also use the -ssh flag to read in a public ssh key file,

go run . -ssh ~/.ssh/id_rsa.pub
go run sha256-hash-file.go -ssh ~/.ssh/id_rsa.pub
go run sha256-hash-file.go -ssh ~/.ssh/id_rsa.pub -loglevel trace

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 sha256,

 ssh-keygen -lf ~/.ssh/id_rsa.pub

TEST

To create _test files,

gotests -w -all sha256-hash-file.go

To unit-tests.sh,

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

INSTALL

Will place an executable in your go bin,

go install sha256-hash-file.go

USAGE

sha256-hash-file {-h|-v|-ssh} [FILENAME] -loglevel [level]

-h

Help,

sha256-hash-file -h

-v

Version,

sha256-hash-file -v

-ssh

Check your public ssh file,

sha256-hash-file -ssh ~/.ssh/id_rsa.pub

-loglevel string

Can use trace, info or error,

sha256-hash-file -ssh ~/.ssh/id_rsa.pub -loglevel trace

FAQs

Package last updated on 16 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts