-
Notifications
You must be signed in to change notification settings - Fork 82
/
example_test.go
42 lines (35 loc) · 983 Bytes
/
example_test.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
// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Keep in sync with ../base32/example_test.go.
package gorsa
import (
"fmt"
"testing"
)
func Test_Example(t *testing.T) {
res, err := GenerateKey(1024)
if err != nil {
fmt.Println(err)
return
}
publicKey := res.PublicKeyBase64
privateKey := res.PrivateKeyBase64
fmt.Println("\n私钥: \n\r" + privateKey)
fmt.Println("\n公钥: \n\r" + publicKey)
fmt.Println("\n私钥加密 —— 公钥解密")
str := `{"domainId":"id", "externalUserId":"test001"}`
fmt.Println("\n\r明文:\r\n" + str)
encodedData, err := PriKeyEncrypt(str, privateKey)
if err != nil {
fmt.Println(err)
return
}
fmt.Println("\n密文:\r\n" + encodedData)
decodedData, err := PublicDecrypt(encodedData, publicKey)
if err != nil {
fmt.Println(err)
return
}
fmt.Println("\n解密后文字: \r\n" + decodedData)
}