|
@@ -4,7 +4,6 @@ import (
|
|
|
codegrpc "analysiscode/client"
|
|
|
"bytes"
|
|
|
"compress/gzip"
|
|
|
- "crypto/aes"
|
|
|
"encoding/base64"
|
|
|
"encoding/json"
|
|
|
"github.com/shopspring/decimal"
|
|
@@ -295,6 +294,29 @@ func (s *Script) LoadScript(site, channel, user *string, code, script_file strin
|
|
|
s.FileLastThreeTimes = append(s.FileLastThreeTimes, end)
|
|
|
return 5
|
|
|
}))
|
|
|
+ //下载、上传base64图片
|
|
|
+ s.L.SetGlobal("downloadBase64File", s.L.NewFunction(func(S *lua.LState) int {
|
|
|
+ url := S.ToString(-3)
|
|
|
+ fileName := S.ToString(-2)
|
|
|
+ base64Img := S.ToString(-1)
|
|
|
+ if fileName == "" {
|
|
|
+ fileName = "文件下载"
|
|
|
+ }
|
|
|
+ fileName = fileName + ".jpg"
|
|
|
+ i := strings.Index(base64Img, ",")
|
|
|
+ dec := base64.NewDecoder(base64.StdEncoding, strings.NewReader(base64Img[i+1:]))
|
|
|
+ ret, err := io.ReadAll(dec)
|
|
|
+ name, size, ftype, fid := "", "", "", ""
|
|
|
+ if err == nil && len(ret) > 0 {
|
|
|
+ url, name, size, ftype, fid = util.UploadFile(s.SCode, fileName, url, ret)
|
|
|
+ }
|
|
|
+ S.Push(lua.LString(url))
|
|
|
+ S.Push(lua.LString(name))
|
|
|
+ S.Push(lua.LString(size))
|
|
|
+ S.Push(lua.LString(ftype))
|
|
|
+ S.Push(lua.LString(fid))
|
|
|
+ return 5
|
|
|
+ }))
|
|
|
//保存验证错误日志
|
|
|
s.L.SetGlobal("saveErrLog", s.L.NewFunction(func(S *lua.LState) int {
|
|
|
code := S.ToString(-4)
|
|
@@ -753,25 +775,49 @@ func (s *Script) LoadScript(site, channel, user *string, code, script_file strin
|
|
|
S.Push(lua.LBool(ok))
|
|
|
return 1
|
|
|
}))
|
|
|
+ //base64加密
|
|
|
+ s.L.SetGlobal("encodeBase64", s.L.NewFunction(func(S *lua.LState) int {
|
|
|
+ text := S.ToString(-1)
|
|
|
+ base64Text := base64.StdEncoding.EncodeToString([]byte(text))
|
|
|
+ S.Push(lua.LString(base64Text))
|
|
|
+ return 1
|
|
|
+ }))
|
|
|
+ //base64解密
|
|
|
+ s.L.SetGlobal("decodeBase64", s.L.NewFunction(func(S *lua.LState) int {
|
|
|
+ text := S.ToString(-1)
|
|
|
+ result := ""
|
|
|
+ byteText, err := base64.StdEncoding.DecodeString(text)
|
|
|
+ if err == nil {
|
|
|
+ result = string(byteText)
|
|
|
+ }
|
|
|
+ S.Push(lua.LString(result))
|
|
|
+ return 1
|
|
|
+ }))
|
|
|
//aes ecb模式加密
|
|
|
s.L.SetGlobal("aesEncryptECB", s.L.NewFunction(func(S *lua.LState) int {
|
|
|
origData := S.ToString(-2)
|
|
|
key := S.ToString(-1)
|
|
|
bytekey := []byte(key)
|
|
|
byteorigData := []byte(origData)
|
|
|
- cipher, _ := aes.NewCipher(generateKey([]byte(bytekey)))
|
|
|
- length := (len(byteorigData) + aes.BlockSize) / aes.BlockSize
|
|
|
- plain := make([]byte, length*aes.BlockSize)
|
|
|
- copy(plain, byteorigData)
|
|
|
- pad := byte(len(plain) - len(byteorigData))
|
|
|
- for i := len(byteorigData); i < len(plain); i++ {
|
|
|
- plain[i] = pad
|
|
|
- }
|
|
|
- encrypted := make([]byte, len(plain))
|
|
|
- // 分组分块加密
|
|
|
- for bs, be := 0, cipher.BlockSize(); bs <= len(byteorigData); bs, be = bs+cipher.BlockSize(), be+cipher.BlockSize() {
|
|
|
- cipher.Encrypt(encrypted[bs:be], plain[bs:be])
|
|
|
- }
|
|
|
+ encrypted := util.AesECBEncrypt(byteorigData, bytekey)
|
|
|
+ result := base64.StdEncoding.EncodeToString(encrypted)
|
|
|
+ S.Push(lua.LString(result))
|
|
|
+ return 1
|
|
|
+ }))
|
|
|
+ //aes ecb模式解密
|
|
|
+ s.L.SetGlobal("aesDecryptECB", s.L.NewFunction(func(S *lua.LState) int {
|
|
|
+ origData := S.ToString(-2)
|
|
|
+ key := S.ToString(-1)
|
|
|
+ data, _ := base64.StdEncoding.DecodeString(origData)
|
|
|
+ result := util.AesECBDecrypter(data, []byte(key))
|
|
|
+ S.Push(lua.LString(result))
|
|
|
+ return 1
|
|
|
+ }))
|
|
|
+ //des ecb模式加密
|
|
|
+ s.L.SetGlobal("desEncryptECB", s.L.NewFunction(func(S *lua.LState) int {
|
|
|
+ origData := S.ToString(-2)
|
|
|
+ key := S.ToString(-1)
|
|
|
+ encrypted := util.DesECBEncrypt([]byte(origData), []byte(key))
|
|
|
result := base64.StdEncoding.EncodeToString(encrypted)
|
|
|
S.Push(lua.LString(result))
|
|
|
return 1
|
|
@@ -780,8 +826,26 @@ func (s *Script) LoadScript(site, channel, user *string, code, script_file strin
|
|
|
s.L.SetGlobal("desDecryptECB", s.L.NewFunction(func(S *lua.LState) int {
|
|
|
origData := S.ToString(-2)
|
|
|
key := S.ToString(-1)
|
|
|
- b, _ := base64.StdEncoding.DecodeString(origData)
|
|
|
- result := util.DesECBDecrypter(b, []byte(key))
|
|
|
+ data, _ := base64.StdEncoding.DecodeString(origData)
|
|
|
+ result := util.DesECBDecrypter(data, []byte(key))
|
|
|
+ S.Push(lua.LString(result))
|
|
|
+ return 1
|
|
|
+ }))
|
|
|
+ //rsa 公钥加密
|
|
|
+ s.L.SetGlobal("rsaEncrypt", s.L.NewFunction(func(S *lua.LState) int {
|
|
|
+ origData := S.ToString(-2)
|
|
|
+ key := S.ToString(-1)
|
|
|
+ encrypted := util.EncryptWithPublicKey([]byte(origData), []byte(key))
|
|
|
+ result := base64.StdEncoding.EncodeToString(encrypted)
|
|
|
+ S.Push(lua.LString(result))
|
|
|
+ return 1
|
|
|
+ }))
|
|
|
+ //rsa 私钥解密
|
|
|
+ s.L.SetGlobal("rsaDecrypt", s.L.NewFunction(func(S *lua.LState) int {
|
|
|
+ origData := S.ToString(-2)
|
|
|
+ key := S.ToString(-1)
|
|
|
+ data, _ := base64.StdEncoding.DecodeString(origData)
|
|
|
+ result := util.DecryptWithPrivateKey(data, []byte(key))
|
|
|
S.Push(lua.LString(result))
|
|
|
return 1
|
|
|
}))
|
|
@@ -840,24 +904,6 @@ func (s *Script) LoadScript(site, channel, user *string, code, script_file strin
|
|
|
S.Push(lua.LString(result))
|
|
|
return 1
|
|
|
}))
|
|
|
- //base64加密
|
|
|
- s.L.SetGlobal("encodeBase64", s.L.NewFunction(func(S *lua.LState) int {
|
|
|
- text := S.ToString(-1)
|
|
|
- base64Text := base64.StdEncoding.EncodeToString([]byte(text))
|
|
|
- S.Push(lua.LString(base64Text))
|
|
|
- return 1
|
|
|
- }))
|
|
|
- //base64解密
|
|
|
- s.L.SetGlobal("decodeBase64", s.L.NewFunction(func(S *lua.LState) int {
|
|
|
- text := S.ToString(-1)
|
|
|
- result := ""
|
|
|
- byteText, err := base64.StdEncoding.DecodeString(text)
|
|
|
- if err == nil {
|
|
|
- result = string(byteText)
|
|
|
- }
|
|
|
- S.Push(lua.LString(result))
|
|
|
- return 1
|
|
|
- }))
|
|
|
//长度
|
|
|
s.L.SetGlobal("stringLen", s.L.NewFunction(func(S *lua.LState) int {
|
|
|
text := S.ToString(-1)
|