forked from nntaoli-project/goex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ParamSignUtils.go
69 lines (60 loc) · 1.48 KB
/
ParamSignUtils.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
package coinapi
import (
"crypto/md5"
"encoding/hex"
"crypto/sha256"
"crypto/hmac"
"crypto/sha512"
"crypto/sha1"
)
/**
*md5签名,okcoin和huobi适用
*/
func GetParamMD5Sign(secret, params string) (string, error) {
hash := md5.New();
_, err := hash.Write([]byte(params));
if err != nil {
return "", err;
}
return hex.EncodeToString(hash.Sum(nil)), nil;
}
func GetSHA(text string) (string, error) {
sha := sha1.New();
_, err := sha.Write([]byte(text))
if err != nil {
return "", err;
}
return hex.EncodeToString(sha.Sum(nil)), nil;
}
func GetParamHmacSHA256Sign(secret, params string) (string, error) {
mac := hmac.New(sha256.New, []byte(secret));
_, err := mac.Write([]byte(params));
if err != nil {
return "", err;
}
return hex.EncodeToString(mac.Sum(nil)), nil;
}
func GetParamHmacSHA512Sign(secret, params string) (string, error) {
mac := hmac.New(sha512.New, []byte(secret));
_, err := mac.Write([]byte(params));
if err != nil {
return "", err;
}
return hex.EncodeToString(mac.Sum(nil)), nil;
}
func GetParamHmacSHA1Sign(secret, params string) (string, error) {
mac := hmac.New(sha1.New, []byte(secret));
_, err := mac.Write([]byte(params));
if err != nil {
return "", err;
}
return hex.EncodeToString(mac.Sum(nil)), nil;
}
func GetParamHmacMD5Sign(secret, params string) (string, error) {
mac := hmac.New(md5.New, []byte(secret));
_, err := mac.Write([]byte(params));
if err != nil {
return "", err;
}
return hex.EncodeToString(mac.Sum(nil)), nil;
}