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 ¶
- func BytesMD5(data []byte) (str string, err error)
- func BytesSHA1(data []byte) (str string, err error)
- func BytesSHA224(data []byte) (str string, err error)
- func BytesSHA256(data []byte) (str string, err error)
- func BytesSHA384(data []byte) (str string, err error)
- func BytesSHA512(data []byte) (str string, err error)
- func BytesSHA512_224(data []byte) (str string, err error)
- func BytesSHA512_256(data []byte) (str string, err error)
- func FileMD5(filePath string) (str string, err error)
- func FileSHA1(filePath string) (str string, err error)
- func FileSHA224(filePath string) (str string, err error)
- func FileSHA256(filePath string) (str string, err error)
- func FileSHA384(filePath string) (str string, err error)
- func FileSHA512(filePath string) (str string, err error)
- func FileSHA512_224(filePath string) (str string, err error)
- func FileSHA512_256(filePath string) (str string, err error)
- func StringMD5(content string) (str string, err error)
- func StringSHA1(content string) (str string, err error)
- func StringSHA224(content string) (str string, err error)
- func StringSHA256(content string) (str string, err error)
- func StringSHA384(content string) (str string, err error)
- func StringSHA512(content string) (str string, err error)
- func StringSHA512_224(content string) (str string, err error)
- func StringSHA512_256(content string) (str string, err error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BytesMD5 ¶
BytesMD5 returns MD5 checksum of the given bytes. N.B. MD5 is cryptographically broken and should not be used for secure applications.
func BytesSHA1 ¶
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 ¶
BytesSHA224 returns SHA-224 checksum of the given bytes.
func BytesSHA256 ¶
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 ¶
BytesSHA384 returns SHA-384 checksum of the given bytes.
func BytesSHA512 ¶
BytesSHA512 returns SHA-512 checksum of the given bytes.
func BytesSHA512_224 ¶
BytesSHA512_224 returns SHA-512/224 checksum of the given bytes.
func BytesSHA512_256 ¶
BytesSHA512_256 returns SHA-512/256 checksum of the given bytes.
func FileMD5 ¶
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 ¶
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 ¶
FileSHA224 returns SHA-224 checksum of the named file.
func FileSHA256 ¶
FileSHA256 returns SHA-256 checksum of the named file.
func FileSHA384 ¶
FileSHA384 returns SHA-384 checksum of the named file.
func FileSHA512 ¶
FileSHA512 returns SHA-512 checksum of the named file.
func FileSHA512_224 ¶
FileSHA512_224 returns SHA-512/224 checksum of the named file.
func FileSHA512_256 ¶
FileSHA512_256 returns SHA-512/256 checksum of the named file.
func StringMD5 ¶
StringMD5 returns MD5 checksum of the given string. N.B. MD5 is cryptographically broken and should not be used for secure applications.
func StringSHA1 ¶
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 ¶
StringSHA224 returns SHA-224 checksum of the given string.
func StringSHA256 ¶
StringSHA256 returns SHA-256 checksum of the given string.
func StringSHA384 ¶
StringSHA384 returns SHA-384 checksum of the given string.
func StringSHA512 ¶
StringSHA512 returns SHA-512 checksum of the given string.
func StringSHA512_224 ¶
StringSHA512_224 returns SHA-512/224 checksum of the given string.
func StringSHA512_256 ¶
StringSHA512_256 returns SHA-512/256 checksum of the given string.
Types ¶
This section is empty.