yhash

package
Version: v0.0.0-...-a823632 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2020 License: MIT Imports: 8 Imported by: 3

Documentation

Overview

Package yhash is yet another collection of helper methods to calculate the checksum of file, string and bytes.

Supported are the FIPS secure hash algorithms SHA-1 (defined in Internet RFC 3174), SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224, and SHA-512/256 (defined in FIPS 180-4) as well as RSA’s MD5 algorithm (defined in Internet RFC 1321).

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesMD5

func BytesMD5(data []byte) (str string, err error)

BytesMD5 returns MD5 checksum of the given bytes. N.B. MD5 is cryptographically broken and should not be used for secure applications.

func BytesSHA1

func BytesSHA1(data []byte) (str string, err error)

BytesSHA1 returns SHA-1 checksum of the given bytes. N.B. SHA-1 is cryptographically broken and should not be used for secure applications.

func BytesSHA224

func BytesSHA224(data []byte) (str string, err error)

BytesSHA224 returns SHA-224 checksum of the given bytes.

func BytesSHA256

func BytesSHA256(data []byte) (str string, err error)

BytesSHA256 returns SHA-256 checksum of the given bytes.

Example

This example calculates SHA-256 checksum of a slice of bytes.

package main

import (
	"fmt"

	"github.com/1set/gut/yhash"
)

func main() {
	hash, err := yhash.BytesSHA256([]byte("This page unintentionally left blank."))
	if err != nil {
		fmt.Println("got error:", err)
		return
	}

	fmt.Println("SHA256:", hash)
}
Output:

SHA256: 19e25cb9879fa4510e6ebfacc8836597429da7d5b279ccc073249492de2eae10

func BytesSHA384

func BytesSHA384(data []byte) (str string, err error)

BytesSHA384 returns SHA-384 checksum of the given bytes.

func BytesSHA512

func BytesSHA512(data []byte) (str string, err error)

BytesSHA512 returns SHA-512 checksum of the given bytes.

func BytesSHA512_224

func BytesSHA512_224(data []byte) (str string, err error)

BytesSHA512_224 returns SHA-512/224 checksum of the given bytes.

func BytesSHA512_256

func BytesSHA512_256(data []byte) (str string, err error)

BytesSHA512_256 returns SHA-512/256 checksum of the given bytes.

func FileMD5

func FileMD5(filePath string) (str string, err error)

FileMD5 returns MD5 checksum of the named file. N.B. MD5 is cryptographically broken and should not be used for secure applications.

Example

This example calculates MD5 checksum of "doc.go" file in current folder.

package main

import (
	"fmt"

	"github.com/1set/gut/yhash"
)

func main() {
	hash, err := yhash.FileMD5("doc.go")
	if err != nil {
		fmt.Println("got error:", err)
		return
	}

	fmt.Println("MD5:", hash)
}
Output:

func FileSHA1

func FileSHA1(filePath string) (str string, err error)

FileSHA1 returns SHA-1 checksum of the named file. N.B. SHA-1 is cryptographically broken and should not be used for secure applications.

func FileSHA224

func FileSHA224(filePath string) (str string, err error)

FileSHA224 returns SHA-224 checksum of the named file.

func FileSHA256

func FileSHA256(filePath string) (str string, err error)

FileSHA256 returns SHA-256 checksum of the named file.

func FileSHA384

func FileSHA384(filePath string) (str string, err error)

FileSHA384 returns SHA-384 checksum of the named file.

func FileSHA512

func FileSHA512(filePath string) (str string, err error)

FileSHA512 returns SHA-512 checksum of the named file.

func FileSHA512_224

func FileSHA512_224(filePath string) (str string, err error)

FileSHA512_224 returns SHA-512/224 checksum of the named file.

func FileSHA512_256

func FileSHA512_256(filePath string) (str string, err error)

FileSHA512_256 returns SHA-512/256 checksum of the named file.

func StringMD5

func StringMD5(content string) (str string, err error)

StringMD5 returns MD5 checksum of the given string. N.B. MD5 is cryptographically broken and should not be used for secure applications.

func StringSHA1

func StringSHA1(content string) (str string, err error)

StringSHA1 returns SHA-1 checksum of the given string. N.B. SHA-1 is cryptographically broken and should not be used for secure applications.

Example

This example calculates SHA-1 checksum of a given string.

package main

import (
	"fmt"

	"github.com/1set/gut/yhash"
)

func main() {
	hash, err := yhash.StringSHA1("This page is intentionally left blank.")
	if err != nil {
		fmt.Println("got error:", err)
		return
	}

	fmt.Println("SHA1:", hash)
}
Output:

SHA1: dfca586074b7cfd24abc19fee213de5558e57422

func StringSHA224

func StringSHA224(content string) (str string, err error)

StringSHA224 returns SHA-224 checksum of the given string.

func StringSHA256

func StringSHA256(content string) (str string, err error)

StringSHA256 returns SHA-256 checksum of the given string.

func StringSHA384

func StringSHA384(content string) (str string, err error)

StringSHA384 returns SHA-384 checksum of the given string.

func StringSHA512

func StringSHA512(content string) (str string, err error)

StringSHA512 returns SHA-512 checksum of the given string.

func StringSHA512_224

func StringSHA512_224(content string) (str string, err error)

StringSHA512_224 returns SHA-512/224 checksum of the given string.

func StringSHA512_256

func StringSHA512_256(content string) (str string, err error)

StringSHA512_256 returns SHA-512/256 checksum of the given string.

Types

This section is empty.

Jump to

Keyboard shortcuts

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