-
Notifications
You must be signed in to change notification settings - Fork 23
/
rsa.go
66 lines (52 loc) · 905 Bytes
/
rsa.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
package rsa
import (
"hash"
"crypto"
"crypto/rsa"
"crypto/sha1"
)
/**
* RSA 加密
*
* @create 2021-8-28
* @author deatil
*/
type RSA struct {
// 私钥
privateKey *rsa.PrivateKey
// 公钥
publicKey *rsa.PublicKey
// 签名验证类型
signHash crypto.Hash
// EncryptOAEP hash.Hash
oaepHash hash.Hash
// EncryptOAEP label
oaepLabel []byte
// [私钥/公钥]数据
keyData []byte
// 传入数据
data []byte
// 解析后的数据
parsedData []byte
// 验证结果
verify bool
// 错误
Errors []error
}
// 构造函数
func NewRSA() RSA {
return RSA{
signHash: crypto.SHA256,
oaepHash: sha1.New(),
verify: false,
Errors: make([]error, 0),
}
}
// 构造函数
func New() RSA {
return NewRSA()
}
var (
// 默认
defaultRSA = NewRSA()
)