Categorygithub.com/sarathkumarsivan/hashutils
repositorypackage
0.1.0
Repository: https://github.com/sarathkumarsivan/hashutils.git
Documentation: pkg.go.dev

# Packages

No description provided by the author
No description provided by the author
No description provided by the author

# README

Build Status codecov Go Report Card GoDoc GitHub issues GitHub

hashutils

This is a collection of hashing utility functions written in Go.

Installation

go get -u github.com/sarathkumarsivan/hashutils

Usage

MD5 Hash

// MD5 Hash with hexadecimal encoding.
hash, _ := MD5Hex("foo")

// MD5 Hash with standard base64 encoding.
hash, _ := MD5Base64StdEnc("foo")

// MD5 Hash with alternate base64 encoding.
hash, _ := MD5Base64URLEnc("foo")

// MD5 Hash with standard raw, unpadded base64 encoding.
hash, _ := MD5Base64RawURLEnc("foo")

// MD5 Hash with unpadded alternate base64 encoding.
hash, _ := MD5Base64RawStdEnc("foo")

// MD5 Hash of file with hexadecimal encoding.
hash, _ := MD5FileHex("foo.txt")

// MD5 Hash of file with standard base64 encoding.
hash, _ := MD5FileBase64StdEnc("foo.txt")

// MD5 Hash of file with alternate base64 encoding.
hash, _ := MD5FileBase64URLEnc("foo.txt")

// MD5 Hash of file with standard raw, unpadded base64 encoding.
hash, _ := MD5FileBase64RawURLEnc("foo.txt")

// MD5 Hash of file with unpadded alternate base64 encoding.
hash, _ := MD5FileBase64RawStdEnc("foo.txt")

SHA1 Hash

// SHA1 Hash with hexadecimal encoding.
hash, _ := SHA1Hex("foo")

// SHA1 Hash with standard base64 encoding.
hash, _ := SHA1Base64StdEnc("foo")

// SHA1 Hash with alternate base64 encoding.
hash, _ := SHA1Base64URLEnc("foo")

// SHA1 Hash with standard raw, unpadded base64 encoding.
hash, _ := SHA1Base64RawURLEnc("foo")

// SHA1 Hash with unpadded alternate base64 encoding.
hash, _ := SHA1Base64RawStdEnc("foo")

// SHA1 Hash of file with hexadecimal encoding.
hash, _ := SHA1FileHex("foo.txt")

// SHA1 Hash of file with standard base64 encoding.
hash, _ := SHA1FileBase64StdEnc("foo.txt")

// SHA1 Hash of file with alternate base64 encoding.
hash, _ := SHA1FileBase64URLEnc("foo.txt")

// SHA1 Hash of file with standard raw, unpadded base64 encoding.
hash, _ := SHA1FileBase64RawURLEnc("foo.txt")

// SHA1 Hash of file with unpadded alternate base64 encoding.
hash, _ := SHA1FileBase64RawStdEnc("foo.txt")

SHA224 Hash

// SHA224 Hash with hexadecimal encoding.
hash, _ := SHA224Hex("foo")

// SHA224 Hash with standard base64 encoding.
hash, _ := SHA224Base64StdEnc("foo")

// SHA224 Hash with alternate base64 encoding.
hash, _ := SHA224Base64URLEnc("foo")

// SHA224 Hash with standard raw, unpadded base64 encoding.
hash, _ := SHA224Base64RawURLEnc("foo")

// SHA224 Hash with unpadded alternate base64 encoding.
hash, _ := SHA224Base64RawStdEnc("foo")

// SHA224 Hash of file with hexadecimal encoding.
hash, _ := SHA224FileHex("foo.txt")

// SHA224 Hash of file with standard base64 encoding.
hash, _ := SHA224FileBase64StdEnc("foo.txt")

// SHA224 Hash of file with alternate base64 encoding.
hash, _ := SHA224FileBase64URLEnc("foo.txt")

// SHA224 Hash of file with standard raw, unpadded base64 encoding.
hash, _ := SHA224FileBase64RawURLEnc("foo.txt")

// SHA224 Hash of file with unpadded alternate base64 encoding.
hash, _ := SHA224BFilease64RawStdEnc("foo.txt")

SHA256 Hash

// SHA256 Hash with hexadecimal encoding.
hash, _ := SHA256Hex("foo")

// SHA256 Hash with standard base64 encoding.
hash, _ := SHA256Base64StdEnc("foo")

// SHA256 Hash with alternate base64 encoding.
hash, _ := SHA256Base64URLEnc("foo")

// SHA256 Hash with standard raw, unpadded base64 encoding.
hash, _ := SHA256Base64RawURLEnc("foo")

// SHA256 Hash with unpadded alternate base64 encoding.
hash, _ := SHA256Base64RawStdEnc("foo")

// SHA256 Hash with hexadecimal encoding.
hash, _ := SHA256FileHex("foo.txt")

// SHA256 Hash of file with standard base64 encoding.
hash, _ := SHA256FileBase64StdEnc("foo.txt")

// SHA256 Hash of file with alternate base64 encoding.
hash, _ := SHA256FileBase64URLEnc("foo.txt")

// SHA256 Hash of file with standard raw, unpadded base64 encoding.
hash, _ := SHA256FileBase64RawURLEnc("foo.txt")

// SHA256 Hash of file with unpadded alternate base64 encoding.
hash, _ := SHA256FileBase64RawStdEnc("foo.txt")

SHA384 Hash

// SHA384 Hash with hexadecimal encoding.
hash, _ := SHA384Hex("foo")

// SHA384 Hash with standard base64 encoding.
hash, _ := SHA384Base64StdEnc("foo")

// SHA384 Hash with alternate base64 encoding.
hash, _ := SHA384Base64URLEnc("foo")

// SHA384 Hash with standard raw, unpadded base64 encoding.
hash, _ := SHA384Base64RawURLEnc("foo")

// SHA384 Hash with unpadded alternate base64 encoding.
hash, _ := SHA384Base64RawStdEnc("foo")

// SHA384 Hash with hexadecimal encoding.
hash, _ := SHA384FileHex("foo.txt")

// SHA384 Hash of file with standard base64 encoding.
hash, _ := SHA384FileBase64StdEnc("foo.txt")

// SHA384 Hash of file with alternate base64 encoding.
hash, _ := SHA384FileBase64URLEnc("foo.txt")

// SHA384 Hash of file with standard raw, unpadded base64 encoding.
hash, _ := SHA384FileBase64RawURLEnc("foo.txt")

// SHA384 Hash of file with unpadded alternate base64 encoding.
hash, _ := SHA384FileBase64RawStdEnc("foo.txt")

SHA512 Hash

// SHA512 Hash with hexadecimal encoding.
hash, _ := SHA512Hex("foo")

// SHA512 Hash with standard base64 encoding.
hash, _ := SHA512Base64StdEnc("foo")

// SHA512 Hash with alternate base64 encoding.
hash, _ := SHA512Base64URLEnc("foo")

// SHA512 Hash with standard raw, unpadded base64 encoding.
hash, _ := SHA512Base64RawURLEnc("foo")

// SHA512 Hash with unpadded alternate base64 encoding.
hash, _ := SHA512Base64RawStdEnc("foo")

// SHA512 Hash with hexadecimal encoding.
hash, _ := SHA512FileHex("foo.txt")

// SHA512 Hash of file with standard base64 encoding.
hash, _ := SHA512FileBase64StdEnc("foo.txt")

// SHA512 Hash of file with alternate base64 encoding.
hash, _ := SHA512FileBase64URLEnc("foo.txt")

// SHA512 Hash of file with standard raw, unpadded base64 encoding.
hash, _ := SHA512FileBase64RawURLEnc("foo.txt")

// SHA512 Hash of file with unpadded alternate base64 encoding.
hash, _ := SHA512FileBase64RawStdEnc("foo.txt")

Install from source and run through commandline

You can make the hash of a text, file/directory by running the command line tool. Install the package from GitHub.

go install github.com/sarathkumarsivan/hashutils

Set the alias in your ~/.profile file and reload the profile as shown below:

# hashutils Path Settings
alias hash="$GOPATH/bin/hashutils $@"
source ~/.profile

Now, you can run hash commands:

hash -t foo

It should display the SHA1 hash of the text "foo" as JSON. SHA1 is used as the default algorithm and results will be encoded in base64 format.

{"text":"foo","algorithm":"sha1","encoding":"hex","hash":"0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33"}

Try specifying the algorithm and encoding like this:

hash -t foo -a md5 -e base64

You should get the MD5 hash of the text "foo" encoded as "base64"

{"text":"foo","algorithm":"md5","encoding":"base64","hash":"rL0Y20zC+Fzt72VPzMSk2A=="}