View Code? Open in Web Editor
NEW
go 常用摘要 Digest Hash 算法库 / go digest hash functions (MD2/MD4/MD5/Hmac/Ripemd160/SHA1/SHA3/SHA256/SM3/kupyna/XXHash/SipHash/Blake3)
Home Page: https://pkg.go.dev/github.com/deatil/go-hash
License: Apache License 2.0
go-hash's People
Contributors
Watchers
go-hash's Issues
Greetings!
There is a problem with the implementations of the Hamsi and Fugue algorithms. They don't support hmac. That is, any key generates the same output:
package main
import (
"crypto/hmac"
"fmt"
"io"
"log"
"os"
"github.com/deatil/go-hash/hamsi"
)
func main() {
if len(os.Args) < 3 {
fmt.Println("Usage: ./hamsi_hmac_tool <path_to_file> <key>")
os.Exit(1)
}
filePath := os.Args[1]
key := []byte(os.Args[2])
file, err := os.Open(filePath)
if err != nil {
log.Fatal("Error opening file:", err)
}
defer file.Close()
h := hmac.New(hamsi.New256, key)
if _, err := io.Copy(h, file); err != nil {
log.Fatal("Error reading file:", err)
}
hashValue := h.Sum(nil)
// Convert hash value to hex string
hashHex := fmt.Sprintf("%x", hashValue)
fmt.Printf("HMAC-Hamsi-256 of file %s: %s\n", filePath, hashHex)
}
Thanks in advance.