You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.4 KiB

package Test
import (
"dsTools/Utils/ConfigUtil"
"dsTools/Utils/MysqlAesUtil"
"encoding/base64"
"fmt"
"github.com/valyala/fasthttp"
"log"
"testing"
)
func TestPage(t *testing.T) {
url := ConfigUtil.EsHost + "/t_sys_loginperson/_search?pretty"
req := &fasthttp.Request{}
req.SetRequestURI(url)
requestBody := []byte(`{"query":{"match_all":{}},"from":1,"size":10}`)
req.SetBody(requestBody)
// 默认是application/x-www-form-urlencoded
req.Header.SetContentType("application/json")
req.Header.SetMethod("POST")
resp := &fasthttp.Response{}
client := &fasthttp.Client{}
if err := client.Do(req, resp); err != nil {
fmt.Println("请求失败:", err.Error())
return
}
b := resp.Body()
fmt.Println("result:\r\n", string(b))
}
func TestAes(t *testing.T) {
// 1、在mysql中使用下面语句可以进行解密
//select idcard_code,aes_decrypt(from_base64(idcard_code),'DsideaL4r5t6y7u!') from t_sys_loginperson limit 100;
// 220183199502155036
//1xrWgRmFUQ2iuj2mYY59tNtpubRtqT7RJqclWDrWISU=
//2、在Golang中是这样使用的
x := []byte("220183199502155036")
key := []byte("DsideaL4r5t6y7u!")
x1 := MysqlAesUtil.AESEncrypt(x, key)
//再对x1进行base64
encodeString := base64.StdEncoding.EncodeToString(x1)
fmt.Println(encodeString)
decodeBytes, err := base64.StdEncoding.DecodeString(encodeString)
if err != nil {
log.Fatalln(err)
}
x2 := MysqlAesUtil.AESDecrypt(decodeBytes, key)
fmt.Print(string(x2))
}