go-hash

module
v1.0.2031 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2024 License: Apache-2.0

README

go-hash

Go Reference

中文 | English

Desc

  • A Go package that get data digest hash
  • hashs has some MD2/MD4/MD5/Hmac/Ripemd160/SHA1/SHA3/SHA256/SM3/Xxhash/Gost etc

Download

go get -u github.com/deatil/go-hash

Get Starting

package main

import (
    "fmt"
    "github.com/deatil/go-hash/hash"
)

func main() {
    var data string = "..."

    // MD5 hash
    var md5String string = hash.
        FromString(data). // input data
        MD5().            // hash type
        ToHexString()     // output data

    // NewMD5 hash
    var md5String string = hash.
        Hashing().
        NewMD5().            // new hash type
        Write([]byte(data)). // write data
        Sum(nil).            // sum
        ToHexString()        // output data

    // =============

    var pass []byte = []byte("...")

    // HmacSHA1 获取摘要
    var hmacMD5String string = hash.
        FromString(data).              // input data
        Hmac(hash.HmacSHA1.New, pass). // hash type
        ToHexString()                  // output data

    // HmacSHA1 获取摘要
    var hmacMD5String string = hash.
        Hashing().                        // input data
        NewHmac(hash.HmacSHA1.New, pass). // hash type
        Write([]byte(data)).              // write data
        Sum(nil).                         // sum
        ToHexString()                     // output data
}

Input and Output

  • Input: FromBytes(data []byte), FromString(data string), FromBase64String(data string), FromHexString(data string), FromReader(reader io.Reader)
  • Output: String() string, ToBytes() []byte, ToString() string, ToBase64String() string, ToHexString() string, ToReader() io.Reader

Hash Types

  • Types: Adler32(), Blake2b_256(), Blake2b_384(), Blake2b_512(), Blake2s_256(), Blake2s_128(), CRC16_X25(), CRC16_Modbus(), CRC32_IEEE(), CRC32_Castagnoli(), CRC32_Koopman(), CRC64_ISO(), CRC64_ECMA(), Fnv32(), Fnv32a(), Fnv64(), Fnv64a(), Fnv128(), Fnv128a(), Hmac(h func() hash.Hash, secret []byte), Keccak256(), Keccak512(), Maphash(), MD2(), MD4(), MD5(), MD5SHA1(), Murmur32(), Murmur32WithSeed(seed uint32), Murmur64(), Murmur64WithSeed(seed uint32), Murmur128(), Murmur128WithSeed(seed uint32), Ripemd160(), SHA1(), SHA224(), SHA256(), SHA384(), SHA512(), SHA512_224(), SHA512_256(), SHA3_224(), SHA3_256(), SHA3_384(), SHA3_512(), Shake128(), Shake256(), SM3(), Xxhash(), Gost34112012256(), Gost34112012512(), HAS160(), LSH256(), LSH256_224(), LSH512(), LSH512_384(), LSH512_256(), LSH512_224(), Siphash64(), Siphash128(), Tiger(), Whirlpool()

  • New Types: NewAdler32(), NewBlake2b_256(key []byte), NewBlake2b_384(key []byte), NewBlake2b_512(key []byte), NewBlake2s_256(key []byte), NewBlake2s_128(key []byte), NewCRC32_IEEE(), NewCRC32_Castagnoli(), NewCRC32_Koopman(), NewCRC64_ISO(), NewCRC64_ECMA(), NewFnv32(), NewFnv32a(), NewFnv64(), NewFnv64a(), NewFnv128(), NewFnv128a(), NewHmac(h func() hash.Hash, secret []byte), NewKeccak256(), NewKeccak512(), NewMaphash(), NewMD2(), NewMD4(), NewMD5(), NewMurmur32(), NewMurmur32WithSeed(seed uint32), NewMurmur64(), NewMurmur64WithSeed(seed uint32), NewMurmur128(), NewMurmur128WithSeed(seed uint32), NewRipemd160(), NewSHA1(), NewSHA224(), NewSHA256(), NewSHA384(), NewSHA512(), NewSHA512_224(), NewSHA512_256(), NewSHA3_224(), NewSHA3_256(), NewSHA3_384(), NewSHA3_512(), NewSM3(), NewXxhash(), NewGost34112012256(), NewGost34112012512(), NewHAS160(), NewLSH256(), NewLSH256_224(), NewLSH512(), NewLSH512_384(), NewLSH512_256(), NewLSH512_224(), NewSiphash64(), NewSiphash128(), NewTiger(), NewWhirlpool()

  • Hmac hashs: HmacADLER32, HmacMD2, HmacMD4, HmacMD5, HmacSHA1, HmacSHA224, HmacSHA256, HmacSHA384, HmacSHA512, HmacSHA512_224, HmacSHA512_256, HmacRIPEMD160, HmacSHA3_224, HmacSHA3_256, HmacSHA3_384, HmacSHA3_512

LICENSE

  • The library LICENSE is Apache2, using the library need keep the LICENSE.

Directories

Path Synopsis
aes
Package aes implements the CMAC MAC with the AES.
Package aes implements the CMAC MAC with the AES.
crc16
x25
Pakcage gmac implements a Galois/Counter Mode (GCM) based MAC, as defined in KS X ISO/IEC 9797-3, NIST SP 800-38D.
Pakcage gmac implements a Galois/Counter Mode (GCM) based MAC, as defined in KS X ISO/IEC 9797-3, NIST SP 800-38D.
gcm
gost
Package jh implements JH-256 algorithm.
Package jh implements JH-256 algorithm.
Package makwa implements the Makwa password hashing algorithm.
Package makwa implements the Makwa password hashing algorithm.
PMAC message authentication code, defined in http://web.cs.ucdavis.edu/~rogaway/ocb/pmac.pdf
PMAC message authentication code, defined in http://web.cs.ucdavis.edu/~rogaway/ocb/pmac.pdf
aes
Package aes implements the PMAC MAC with the AES.
Package aes implements the PMAC MAC with the AES.
Package rabin implements Rabin hashing (fingerprinting).
Package rabin implements Rabin hashing (fingerprinting).
Package skein implements the Skein512 hash function based on the Threefish tweakable block cipher.
Package skein implements the Skein512 hash function based on the Threefish tweakable block cipher.
skein1024
Package skein1024 implements the Skein1024 hash function based on the Threefish1024 tweakable block cipher.
Package skein1024 implements the Skein1024 hash function based on the Threefish1024 tweakable block cipher.
skein256
Package skein256 implements the Skein256 hash function based on the Threefish256 tweakable block cipher.
Package skein256 implements the Skein256 hash function based on the Threefish256 tweakable block cipher.
threefish
Package threefish implements the Threefish tweakable block cipher.
Package threefish implements the Threefish tweakable block cipher.
Package skein implements the Skein-512 hash function, MAC, and stream cipher as defined in "The Skein Hash Function Family, v1.3".
Package skein implements the Skein-512 hash function, MAC, and stream cipher as defined in "The Skein Hash Function Family, v1.3".
xxhash

Jump to

Keyboard shortcuts

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