This repository has been archived by the owner on Aug 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
/
handle_hash.go
88 lines (78 loc) · 1.74 KB
/
handle_hash.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright 2017-2018 The qitmeer developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package qx
import (
"crypto"
"encoding/hex"
"fmt"
"github.com/Qitmeer/qitmeer/common/hash"
"github.com/Qitmeer/qitmeer/common/hash/btc"
"github.com/Qitmeer/qitmeer/common/hash/dcr"
)
func Sha256(input string) {
data, err := hex.DecodeString(input)
if err != nil {
ErrExit(err)
}
fmt.Printf("%x\n", btc.HashB(data))
}
func Blake256(input string) {
data, err := hex.DecodeString(input)
if err != nil {
ErrExit(err)
}
fmt.Printf("%x\n", dcr.HashB(data))
}
func Blake2b256(input string) {
data, err := hex.DecodeString(input)
if err != nil {
ErrExit(err)
}
fmt.Printf("%x\n", hash.HashB(data))
}
func Blake2b512(input string) {
data, err := hex.DecodeString(input)
if err != nil {
ErrExit(err)
}
fmt.Printf("%x\n", hash.Hash512B(data))
}
func Sha3_256(input string) {
data, err := hex.DecodeString(input)
if err != nil {
ErrExit(err)
}
fmt.Printf("%x\n", hash.CalcHash(data, hash.GetHasher(hash.SHA3_256)))
}
func Keccak256(input string) {
data, err := hex.DecodeString(input)
if err != nil {
ErrExit(err)
}
fmt.Printf("%x\n", hash.CalcHash(data, hash.GetHasher(hash.Keccak_256)))
}
func Ripemd160(input string) {
data, err := hex.DecodeString(input)
if err != nil {
ErrExit(err)
}
hasher := crypto.RIPEMD160.New()
hasher.Write(data)
hash := hasher.Sum(nil)
fmt.Printf("%x\n", hash[:])
}
func Bitcoin160(input string) {
data, err := hex.DecodeString(input)
if err != nil {
ErrExit(err)
}
fmt.Printf("%x\n", btc.Hash160(data))
}
func Hash160(input string) {
data, err := hex.DecodeString(input)
if err != nil {
ErrExit(err)
}
fmt.Printf("%x\n", hash.Hash160(data))
}