hashing

package module
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2023 License: MIT Imports: 4 Imported by: 0

README

hashing

Go Go Version GoDoc codecov Go Report Card tests MIT license

Installation

go get github.com/go-packagist/hashing/v2

Usage

package main

import (
	"fmt"
	"github.com/go-packagist/hashing/v2"
)

func main() {
	// Example1: use md5 hasher
	md5Hashed, err := hashing.Md5.Make("123456")
	if err != nil {
		panic(err)
	}
	fmt.Println(md5Hashed)                              // e10adc3949ba59abbe56e057f20f883e
	fmt.Println(hashing.Md5.Check("123456", md5Hashed)) // true

	// Example2: use bcrypt hasher
	bcryptHashed, err := hashing.Bcrypt.Make("123456")
	if err != nil {
		panic(err)
	}
	fmt.Println(bcryptHashed)
	fmt.Println(hashing.Bcrypt.Check("123456", bcryptHashed)) // true

	// Example3: use sha1 hasher with cost
	sha1Hashed, err := hashing.Sha1.Make("123456")
	if err != nil {
		panic(err)
	}
	fmt.Println(sha1Hashed)
	fmt.Println(hashing.Sha1.Check("123456", sha1Hashed)) // true
}

License

The MIT License (MIT). Please see License File for more information.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hasher

type Hasher interface {
	// Make a hash value from the given value.
	Make(value string) (string, error)

	// MustMake a hash value from the given value.
	// If an error occurs, it will panic.
	MustMake(value string) string

	// Check the given value matches the given hashed value.
	// If Make() is error, it will return false.
	Check(value, hashedValue string) bool
}
var Bcrypt Hasher = &bcryptHasher{}
var Md5 Hasher = &md5Hasher{}
var Sha1 Hasher = &sha1Hasher{}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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