hasher

package
v0.0.0-...-c1d82b4 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2019 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func FileSum

func FileSum(file string) (hash string, err error)

FileSum restituisce il chacksum hash della stringa passata come argomento.

Example
package main

import (
	"fmt"
	"log"
	"os"

	"github.com/axamon/hermes/hasher"
)

func main() {
	testfile := "test.zip"
	flags := os.O_WRONLY | os.O_CREATE | os.O_TRUNC
	file, err := os.OpenFile(testfile, flags, 0644)
	if err != nil {
		log.Fatalf("Failed to open zip for writing: %s", err)
	}

	file.Write([]byte("pippo"))

	file.Close()

	hash, err := hasher.FileSum(testfile)
	if err != nil {
		log.Printf("ERROR Impossibile ricavare hash del file %s: %s\n", testfile, err.Error())
	}

	fmt.Println(hash)

	err = os.Remove(testfile)
	if err != nil {
		log.Fatalf("ERROR impossibile cancellare file di test %s: %s\n", testfile, err.Error())
	}
}
Output:

a2242ead55c94c3deb7cf2340bfef9d5bcaca22dfe66e646745ee4371c633fc8

func FileWithSeed

func FileWithSeed(file, seed string) (hash string, err error)

FileWithSeed restituisce il chacksum hash del file passato come argomento a cui viene aggiunto un seed.

Example
package main

import (
	"fmt"
	"log"
	"os"

	"github.com/axamon/hermes/hasher"
)

func main() {
	testfile := "test.zip"
	flags := os.O_WRONLY | os.O_CREATE | os.O_TRUNC
	file, err := os.OpenFile(testfile, flags, 0644)
	if err != nil {
		log.Fatalf("Failed to open zip for writing: %s", err)
	}
	defer func() {
		err = os.Remove(testfile)

		if err != nil {
			log.Fatalf("ERROR impossibile cancellare file di test %s: %s\n", testfile, err.Error())
		}
	}()

	file.Write([]byte("pippo"))

	file.Close()

	hash, err := hasher.FileWithSeed(testfile, "vvkidtbcjujhttuuikvjtfhilrkfkkfgejcktriignbr")
	if err != nil {
		log.Printf("ERROR Impossibile ricavare hash del file %s più seed: %s\n", testfile, err.Error())
	}

	fmt.Println(hash)

}
Output:

76766b69647462636a756a6874747575696b766a746668696c726b666b6b6667656a636b74726969676e6272a2242ead55c94c3deb7cf2340bfef9d5bcaca22dfe66e646745ee4371c633fc8

func StringSum

func StringSum(str string) (hash string, err error)

StringSum restituisce il chacksum hash della stringa passata come argomento.

func StringSumWithSalt

func StringSumWithSalt(str, salt string) (hash string, err error)

StringSumWithSalt restituisce il chacksum hash della stringa passata come argomento più un seed personalizzato.

Types

This section is empty.

Jump to

Keyboard shortcuts

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