37 lines
656 B
Go
37 lines
656 B
Go
package aes
|
|
|
|
import (
|
|
"encoding/hex"
|
|
"testing"
|
|
)
|
|
|
|
func TestSecret(t *testing.T) {
|
|
textA := "我是王德法"
|
|
textABytes := []byte(textA)
|
|
|
|
token, err := AesEcrypt(textABytes, PwdKey)
|
|
if err != nil {
|
|
t.Errorf("加密错误 %s", err.Error())
|
|
}
|
|
|
|
//fmt.Println(token)
|
|
tokenStr := hex.EncodeToString(token)
|
|
|
|
tokenByte, err := hex.DecodeString(tokenStr)
|
|
if err != nil {
|
|
t.Errorf("hex加密错误 %s", err.Error())
|
|
}
|
|
|
|
res, err := AesDeCrypt(tokenByte, PwdKey)
|
|
if err != nil {
|
|
t.Errorf("解密错误 %s", err.Error())
|
|
}
|
|
|
|
if string(res) == textA {
|
|
t.Logf("加解密通过 %s", string(res))
|
|
} else {
|
|
t.Errorf("解析内容不符合")
|
|
}
|
|
|
|
}
|