forked from wenzhenxi/gorsa
-
Notifications
You must be signed in to change notification settings - Fork 2
/
gorsaSign.go
60 lines (49 loc) · 1.43 KB
/
gorsaSign.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
package gorsa
// 使用RSAWithMD5算法签名
func SignMd5WithRsa(data string, privateKey string) (string, error) {
grsa := RSASecurity{}
grsa.SetPrivateKey(privateKey)
sign, err := grsa.SignMd5WithRsa(data)
if err != nil {
return "", err
}
return sign, err
}
// 使用RSAWithSHA1算法签名
func SignSha1WithRsa(data string, privateKey string) (string, error) {
grsa := RSASecurity{}
grsa.SetPrivateKey(privateKey)
sign, err := grsa.SignSha1WithRsa(data)
if err != nil {
return "", err
}
return sign, err
}
// 使用RSAWithSHA256算法签名
func SignSha256WithRsa(data string, privateKey string) (string, error) {
grsa := RSASecurity{}
grsa.SetPrivateKey(privateKey)
sign, err := grsa.SignSha256WithRsa(data)
if err != nil {
return "", err
}
return sign, err
}
// 使用RSAWithMD5验证签名
func VerifySignMd5WithRsa(data string, signData string, publicKey string) error {
grsa := RSASecurity{}
grsa.SetPublicKey(publicKey)
return grsa.VerifySignMd5WithRsa(data, signData)
}
// 使用RSAWithSHA1验证签名
func VerifySignSha1WithRsa(data string, signData string, publicKey string) error {
grsa := RSASecurity{}
grsa.SetPublicKey(publicKey)
return grsa.VerifySignSha1WithRsa(data, signData)
}
// 使用RSAWithSHA256验证签名
func VerifySignSha256WithRsa(data string, signData string, publicKey string) error {
grsa := RSASecurity{}
grsa.SetPublicKey(publicKey)
return grsa.VerifySignSha256WithRsa(data, signData)
}