From ba5bc48de179cfd67b728c117f5020165666ea03 Mon Sep 17 00:00:00 2001 From: 0xbcdev <0xbcdev@bcdev.tools> Date: Thu, 11 Apr 2024 06:16:06 +0700 Subject: [PATCH] hashing tool keccak512 --- README.md | 1 + cmd/hash/keccak256.go | 4 ++-- cmd/hash/keccak512.go | 24 ++++++++++++++++++++++++ cmd/hash/root.go | 1 + 4 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 cmd/hash/keccak512.go diff --git a/README.md b/README.md index 3865970..79bca68 100644 --- a/README.md +++ b/README.md @@ -124,6 +124,7 @@ devd convert decode_base64 [base64] ```bash devd hash md5 [input] devd hash keccak256 [input] +devd hash keccak512 [input] ``` ### Debug tools diff --git a/cmd/hash/keccak256.go b/cmd/hash/keccak256.go index 88772ec..c70673f 100644 --- a/cmd/hash/keccak256.go +++ b/cmd/hash/keccak256.go @@ -15,8 +15,8 @@ func GetKeccak256Command() *cobra.Command { Args: cobra.ExactArgs(1), Run: func(_ *cobra.Command, args []string) { input := strings.Join(args, " ") - hash := crypto.Keccak256Hash([]byte(input)) - fmt.Println(hex.EncodeToString(hash.Bytes())) + hash := crypto.Keccak256([]byte(input)) + fmt.Println(hex.EncodeToString(hash)) }, } diff --git a/cmd/hash/keccak512.go b/cmd/hash/keccak512.go new file mode 100644 index 0000000..94d1e3e --- /dev/null +++ b/cmd/hash/keccak512.go @@ -0,0 +1,24 @@ +package hash + +import ( + "encoding/hex" + "fmt" + "github.com/ethereum/go-ethereum/crypto" + "github.com/spf13/cobra" + "strings" +) + +func GetKeccak512Command() *cobra.Command { + cmd := &cobra.Command{ + Use: "keccak512 [input]", + Short: "keccak512 hashing input", + Args: cobra.ExactArgs(1), + Run: func(_ *cobra.Command, args []string) { + input := strings.Join(args, " ") + hash := crypto.Keccak512([]byte(input)) + fmt.Println(hex.EncodeToString(hash)) + }, + } + + return cmd +} diff --git a/cmd/hash/root.go b/cmd/hash/root.go index 0767309..928aab4 100644 --- a/cmd/hash/root.go +++ b/cmd/hash/root.go @@ -14,6 +14,7 @@ func Commands() *cobra.Command { cmd.AddCommand( GetMd5Command(), GetKeccak256Command(), + GetKeccak512Command(), ) return cmd