Skip to content

Instantly share code, notes, and snippets.

@miguelmota
Last active September 24, 2022 02:26
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miguelmota/01d051b2208ea706a273dbf0dd673844 to your computer and use it in GitHub Desktop.
Save miguelmota/01d051b2208ea706a273dbf0dd673844 to your computer and use it in GitHub Desktop.
Ethereum Sha3 (Keccak256) in Golang
package main
import (
"encoding/hex"
"fmt"
"github.com/ethereum/go-ethereum/crypto/sha3"
)
func main() {
hash := sha3.NewKeccak256()
var buf []byte
//hash.Write([]byte{0xcc})
hash.Write(decodeHex("cc"))
buf = hash.Sum(nil)
fmt.Println(hex.EncodeToString(buf))
//expected := "EEAD6DBFC7340A56CAEDC044696A168870549A6A7F6F56961E84A54BD9970B8A"
}
func decodeHex(s string) []byte {
b, err := hex.DecodeString(s)
if err != nil {
panic(err)
}
return b
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment