forked from go-pay/gopay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alipay_server_api.go
68 lines (61 loc) · 1.39 KB
/
alipay_server_api.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
//==================================
// * Name:Jerry
// * DateTime:2019/6/18 19:24
// * Desc:
//==================================
package gopay
import "bytes"
//格式化秘钥
func FormatPrivateKey(privateKey string) (pKey string) {
buffer := new(bytes.Buffer)
buffer.WriteString("-----BEGIN RSA PRIVATE KEY-----\n")
rawLen := 64
keyLen := len(privateKey)
raws := keyLen / rawLen
temp := keyLen % rawLen
if temp > 0 {
raws++
}
start := 0
end := start + rawLen
for i := 0; i < raws; i++ {
if i == raws-1 {
buffer.WriteString(privateKey[start:])
} else {
buffer.WriteString(privateKey[start:end])
}
buffer.WriteString("\n")
start += rawLen
end = start + rawLen
}
buffer.WriteString("-----END RSA PRIVATE KEY-----\n")
pKey = buffer.String()
return
}
//格式化秘钥
func FormatAliPayPublicKey(publickKey string) (pKey string) {
buffer := new(bytes.Buffer)
buffer.WriteString("-----BEGIN PUBLIC KEY-----\n")
rawLen := 64
keyLen := len(publickKey)
raws := keyLen / rawLen
temp := keyLen % rawLen
if temp > 0 {
raws++
}
start := 0
end := start + rawLen
for i := 0; i < raws; i++ {
if i == raws-1 {
buffer.WriteString(publickKey[start:])
} else {
buffer.WriteString(publickKey[start:end])
}
buffer.WriteString("\n")
start += rawLen
end = start + rawLen
}
buffer.WriteString("-----END PUBLIC KEY-----\n")
pKey = buffer.String()
return
}