Last active
September 24, 2022 02:26
-
-
Save miguelmota/01d051b2208ea706a273dbf0dd673844 to your computer and use it in GitHub Desktop.
Ethereum Sha3 (Keccak256) in Golang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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