Переглянути джерело

test encode message and decode it successful

master
Patrick Peng Sun 8 роки тому
джерело
коміт
727dc06f0c
2 змінених файлів з 5 додано та 9 видалено
  1. +3
    -2
      main.go
  2. +2
    -7
      messageEncrypt.go

+ 3
- 2
main.go Переглянути файл

@@ -25,11 +25,12 @@ func main() {
<Event><![CDATA[CLICK]]></Event>
<EventKey><![CDATA[V1001_TODAY_MUSIC]]></EventKey>
</xml>`
m := Decode(txt)
t := Encode(msg)
m := Decode(t)

fmt.Println(t)
fmt.Println(m)
fmt.Println(t == txt)
fmt.Println(m == msg)

return

+ 2
- 7
messageEncrypt.go Переглянути файл

@@ -8,12 +8,10 @@ import (
"fmt"
)

var random16 []byte

//Encode convert a xml sequence into encrypted message
func Encode(s string) string {

d := aesEncryptMsg(random16, []byte(s), APIConfig.Appid, getAesEncryptKey())
d := aesEncryptMsg(random16Byte(), []byte(s), APIConfig.Appid, getAesEncryptKey())
r := base64.StdEncoding.EncodeToString(d)
fmt.Println(r)
return r
@@ -24,11 +22,8 @@ func Decode(s string) string {

r, _ := base64.StdEncoding.DecodeString(s)

r16, raw, err := aesDecryptMsg([]byte(r), APIConfig.Appid, getAesEncryptKey())
random16 = make([]byte, 16)
copy(random16, r16)
_, raw, err := aesDecryptMsg([]byte(r), APIConfig.Appid, getAesEncryptKey())
if err == nil {
fmt.Println(string(raw))
return string(raw)
}
return ""

Завантаження…
Відмінити
Зберегти