|
|
@@ -12,11 +12,101 @@ func TestCompare(t *testing.T) {
|
|
12
|
12
|
|
|
13
|
13
|
ksm := KeyShareMsg{Message: Message{from: "1.1.1.1", version: "1", time: "2", kind: 1}, key: "1234"}
|
|
14
|
14
|
sm.RegKey(ksm)
|
|
15
|
|
- sm.GetNodeKey(ksm.Message)
|
|
16
|
|
- fmt.Println(sm.GetNodeKey(ksm.Message))
|
|
|
15
|
+ sm.GetNodeKey(ksm.Message.From())
|
|
|
16
|
+ fmt.Println(sm.GetNodeKey(ksm.Message.From()))
|
|
17
|
17
|
var targetKey []int64
|
|
18
|
18
|
targetKey = []int64{1234, 1235, 1236}
|
|
19
|
|
- fmt.Println(sm.ReEncrypt(sm.GetNodeKey(ksm.Message), 0, targetKey))
|
|
20
|
|
- fmt.Println(sm.CompareDigit(1236, 1234))
|
|
|
19
|
+ fmt.Println(sm.ReEncrypt(sm.GetNodeKey(ksm.Message.From()), 0, targetKey))
|
|
|
20
|
+ //fmt.Println(sm.CompareDigit(1236, 1234))
|
|
21
|
21
|
|
|
22
|
22
|
}
|
|
|
23
|
+
|
|
|
24
|
+func CreatePubMsg(msg Message, topic string, value string, content string) *PublishMsg {
|
|
|
25
|
+ toPubMsg := new(PublishMsg)
|
|
|
26
|
+ toPubMsg.Message = msg
|
|
|
27
|
+
|
|
|
28
|
+ intArr := []rune(topic)
|
|
|
29
|
+ fmt.Print("topic length ")
|
|
|
30
|
+ fmt.Println(len(intArr))
|
|
|
31
|
+ fmt.Println(len(toPubMsg.topic))
|
|
|
32
|
+ for index := 0; index < len(intArr); index++ {
|
|
|
33
|
+ toPubMsg.topic = append(toPubMsg.topic, int64(intArr[index]))
|
|
|
34
|
+ }
|
|
|
35
|
+ fmt.Println(len(toPubMsg.topic))
|
|
|
36
|
+ intArr = []rune(value)
|
|
|
37
|
+ for index := 0; index < len(intArr); index++ {
|
|
|
38
|
+ toPubMsg.value = append(toPubMsg.value, int64(intArr[index]))
|
|
|
39
|
+ }
|
|
|
40
|
+ intArr = []rune(content)
|
|
|
41
|
+ for index := 0; index < len(intArr); index++ {
|
|
|
42
|
+ toPubMsg.content = append(toPubMsg.content, int64(intArr[index]))
|
|
|
43
|
+ }
|
|
|
44
|
+
|
|
|
45
|
+ return toPubMsg
|
|
|
46
|
+}
|
|
|
47
|
+
|
|
|
48
|
+func EncryptionMsg(msg *PublishMsg, gyKey int64, privateKey int64) PublishMsg {
|
|
|
49
|
+ for index := range msg.topic {
|
|
|
50
|
+ msg.topic[index] = msg.topic[index] + gyKey
|
|
|
51
|
+ }
|
|
|
52
|
+ for index := range msg.value {
|
|
|
53
|
+ msg.value[index] = msg.value[index] + gyKey
|
|
|
54
|
+ }
|
|
|
55
|
+ for index := range msg.content {
|
|
|
56
|
+ msg.content[index] = msg.content[index] + gyKey + privateKey
|
|
|
57
|
+ }
|
|
|
58
|
+
|
|
|
59
|
+ return *msg
|
|
|
60
|
+}
|
|
|
61
|
+
|
|
|
62
|
+func DecryptionMsg(msg *PublishMsg, gyKey int64, privateKey int64) {
|
|
|
63
|
+ for index := range msg.topic {
|
|
|
64
|
+ msg.topic[index] = msg.topic[index] - gyKey - privateKey
|
|
|
65
|
+ }
|
|
|
66
|
+ for index := range msg.value {
|
|
|
67
|
+ msg.value[index] = msg.value[index] - gyKey - privateKey
|
|
|
68
|
+ }
|
|
|
69
|
+ for index := range msg.content {
|
|
|
70
|
+ msg.content[index] = msg.content[index] - gyKey - privateKey
|
|
|
71
|
+ }
|
|
|
72
|
+
|
|
|
73
|
+ var runeArr []rune
|
|
|
74
|
+ for index := range msg.topic {
|
|
|
75
|
+ runeArr = append(runeArr, rune(int(msg.topic[index])))
|
|
|
76
|
+ }
|
|
|
77
|
+ fmt.Println("\n\ntopic is: " + string(runeArr))
|
|
|
78
|
+ runeArr = nil
|
|
|
79
|
+
|
|
|
80
|
+ for index := range msg.value {
|
|
|
81
|
+ runeArr = append(runeArr, rune(int(msg.value[index])))
|
|
|
82
|
+ }
|
|
|
83
|
+ fmt.Println("value is: " + string(runeArr))
|
|
|
84
|
+ runeArr = nil
|
|
|
85
|
+
|
|
|
86
|
+ for index := range msg.content {
|
|
|
87
|
+ runeArr = append(runeArr, rune(int(msg.content[index])))
|
|
|
88
|
+ }
|
|
|
89
|
+ fmt.Println("content is: " + string(runeArr))
|
|
|
90
|
+ runeArr = nil
|
|
|
91
|
+
|
|
|
92
|
+}
|
|
|
93
|
+
|
|
|
94
|
+// from "1.1.1.1" to "3.3.3.3" node
|
|
|
95
|
+func TestReEnc(t *testing.T) {
|
|
|
96
|
+ var security = NewSecurity()
|
|
|
97
|
+ var sm SecurityManager
|
|
|
98
|
+ sm = security
|
|
|
99
|
+ security.KeyMap["1.1.1.1"] = "5678"
|
|
|
100
|
+ security.KeyMap["3.3.3.3"] = "9999"
|
|
|
101
|
+
|
|
|
102
|
+ fmt.Println(sm.GetNodeKey("3.3.3.3"))
|
|
|
103
|
+ msg := Message{from: "1.1.1.1", version: "1", time: "123", kind: 1}
|
|
|
104
|
+ fmt.Println(msg)
|
|
|
105
|
+ publishMsg := CreatePubMsg(msg, "soccer123한글", "playerList", "son and 10 players")
|
|
|
106
|
+ fmt.Println(publishMsg)
|
|
|
107
|
+ encPublishMsg := EncryptionMsg(publishMsg, 1234, 5678)
|
|
|
108
|
+ fmt.Println(encPublishMsg)
|
|
|
109
|
+ reEncPublishMsg := sm.ReEncPubMsg(encPublishMsg, "3.3.3.3")
|
|
|
110
|
+ fmt.Println(reEncPublishMsg)
|
|
|
111
|
+ DecryptionMsg(reEncPublishMsg, 1234, 9999)
|
|
|
112
|
+}
|