-
Notifications
You must be signed in to change notification settings - Fork 25
/
ecdsa.go
68 lines (54 loc) · 937 Bytes
/
ecdsa.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
package ecdsa
import (
"hash"
"crypto/ecdsa"
"crypto/elliptic"
"crypto/sha256"
)
type (
// HashFunc
HashFunc = func() hash.Hash
)
/**
* ECDSA
*
* @create 2022-4-3
* @author deatil
*/
type ECDSA struct {
// 私钥
privateKey *ecdsa.PrivateKey
// 公钥
publicKey *ecdsa.PublicKey
// 生成类型
curve elliptic.Curve
// 签名验证类型
signHash HashFunc
// [私钥/公钥]数据
keyData []byte
// 传入数据
data []byte
// 解析后的数据
parsedData []byte
// 验证结果
verify bool
// 错误
Errors []error
}
// 构造函数
func NewECDSA() ECDSA {
return ECDSA{
curve: elliptic.P256(),
signHash: sha256.New,
verify: false,
Errors: make([]error, 0),
}
}
// 构造函数
func New() ECDSA {
return NewECDSA()
}
var (
// 默认
defaultECDSA = NewECDSA()
)