-
Notifications
You must be signed in to change notification settings - Fork 22
/
sign.go
42 lines (32 loc) · 838 Bytes
/
sign.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
package ed448
import (
"errors"
"crypto/rand"
"github.com/deatil/go-cryptobin/ed448"
)
// 私钥签名
func (this ED448) Sign() ED448 {
if this.privateKey == nil {
err := errors.New("privateKey empty.")
return this.AppendError(err)
}
sig, err := this.privateKey.Sign(rand.Reader, this.data, this.options)
if err != nil {
return this.AppendError(err)
}
this.parsedData = []byte(sig)
return this
}
// 公钥验证
func (this ED448) Verify(data []byte) ED448 {
if this.publicKey == nil {
err := errors.New("publicKey empty.")
return this.AppendError(err)
}
err := ed448.VerifyWithOptions(this.publicKey, data, this.data, this.options)
if err != nil {
return this.AppendError(err)
}
this.verify = true
return this
}