/
encrypt.go
executable file
·54 lines (44 loc) · 1.04 KB
/
encrypt.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
package util
import (
"crypto/sha256"
"encoding/base64"
"github.com/btcsuite/btcutil/base58"
"golang.org/x/crypto/ripemd160"
)
func SHA256(message []byte) []byte {
hash := sha256.New()
hash.Write(message)
bytes := hash.Sum(nil)
return bytes
}
func DoubleSHA256(message []byte) []byte {
return SHA256(SHA256(message))
}
// See https://en.wikipedia.org/wiki/Base64
func Base64(b []byte) string {
return base64.StdEncoding.EncodeToString(b)
}
func Base64Decode(s string) ([]byte, error) {
b, err := base64.StdEncoding.DecodeString(s)
if err != nil {
return nil, err
}
return b, nil
}
// See https://en.wikipedia.org/wiki/Base58
func Base58(b []byte) string {
return base58.Encode(b)
}
// Base58Decode returns base 58 decodes the argument and returns the result.
func Base58Decode(s string) []byte {
return base58.Decode(s)
}
// See https://en.wikipedia.org/wiki/RIPEMD
func Ripemd160(b []byte) []byte {
hasher := ripemd160.New()
hasher.Write(b)
return hasher.Sum(nil)
}
func Hash160(b []byte) []byte {
return Ripemd160(SHA256(b))
}