hash

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 18, 2023 License: MIT Imports: 11 Imported by: 0

README

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")
  }
}

Documentation

Overview

Package hash is wrapper package around argon2

Derived from Alex Edwards's code

@origin https://gist.github.com/alexedwards/34277fae0f48abe36822b375f0f6a621

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidHash         = errors.New("the encoded hash is not in the correct format")
	ErrIncompatibleVersion = errors.New("incompatible version of argon2")
)

Errors

Functions

func Run

func Run(text string) (hashed string, err error)

Run hashes a text with argon2 algorithm

func RunFile

func RunFile(filepath string) (string, error)

RunFile hashes a file with sha1 algorithm

Returns hex encoded string representation

func RunSha1

func RunSha1(str ...string) string

RunSha1 hashes strings with sha1 algorithm

RunSha1 can take more than one string; the order of param matters

Returns hex encoded string representation

func Verify

func Verify(plaintext, hashed string) (match bool, err error)

Verify the hash with argon2 algorithm

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL