junekimdev / hash

Hash algorithms in Golang

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Hash

Hash algorithms in Golang

PkgGoDev Go Report Card GitHub tag (latest by date) GitHub


Getting Started

Installing

go get it (pun intended 😸)

go get github.com/junekimdev/hash

Usage

package main

import (
  "log"

  "github.com/junekimdev/hash"
)


func main() {
  // Got password over https
  // Hash it to store
  hashedPassword, err := Run(password)
  if err != nil {
    log.Println(err)
  }

  // Got password over https &
  // Got store password from DB
  // Verify it
  match, err := Verify(password, hashedPassword)
  if err != nil {
    log.Println(err)
  }

  // Hashing a file with sha1 algorithm
  filename := "HASH_ME.txt"
  if hashedFile, err := RunFile(filename); err != nil {
    log.Println(err)
  }
  // Use hashedFile to evaluate equality of two files
  // like what GIT does...

  // Lightweight but risky hashing
  // SHA1 algorithm is not considered as a secure algorithm at this moment of time
  // But there are many use cases SHA1 algorithm can be useful

  // RunSha1 can take more than one string; order matters
  hash1 := RunSha1(input1, input2)
  hash2 := RunSha1(input3, input4)
  if hash1 == hash2 {
    log.Println("Same inputs")
  }
}

About

Hash algorithms in Golang

License:MIT License


Languages

Language:Go 100.0%