-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathECDSA_test.go
More file actions
55 lines (47 loc) · 1.01 KB
/
ECDSA_test.go
File metadata and controls
55 lines (47 loc) · 1.01 KB
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
package u_test
import (
"bytes"
"fmt"
"testing"
"time"
"github.com/ssgo/u"
)
func TestSign(t *testing.T) {
priKeyBuf, pubKeyBuf, err := u.GenerateECDSAKeyPair(521)
if err != nil {
t.Fatal(err.Error())
}
ecdsa, _ := u.NewECDSAndEraseKey(priKeyBuf, pubKeyBuf)
okCount := 0
testCount := 100
t1 := time.Now()
for i := 0; i < testCount; i++ {
data := u.MakeToken(10)
sign, err := ecdsa.Sign(data)
if err != nil {
t.Fatal(err.Error())
}
if ok, err := ecdsa.Verify(data, sign); ok && err == nil {
okCount++
}
}
if okCount != testCount {
t.Fatal("VerifyECDSA Error " + u.String(okCount))
}
t2 := time.Now()
fmt.Println(okCount, testCount, t2.Sub(t1))
data := u.MakeToken(10)
crypted, err := ecdsa.Encrypt(data)
if err != nil {
t.Fatal(err)
}
decryptedData, err := ecdsa.Decrypt(crypted)
t3 := time.Now()
fmt.Println("DecryptECDSA Time:", t3.Sub(t2))
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(decryptedData, data) {
t.Fatal("DecryptECDSA Error", decryptedData, data)
}
}