|
@@ -10,7 +10,6 @@ import (
|
|
|
codegrpc "analysiscode/client"
|
|
|
"bytes"
|
|
|
"compress/gzip"
|
|
|
- "crypto/aes"
|
|
|
"encoding/base64"
|
|
|
"encoding/json"
|
|
|
"github.com/shopspring/decimal"
|
|
@@ -307,7 +306,6 @@ func (s *Script) LoadScript(site, channel, user *string, code, script_file strin
|
|
|
// s.FileLastThreeTimes = append(s.FileLastThreeTimes, end)
|
|
|
// return 5
|
|
|
//}))
|
|
|
-
|
|
|
//附件大小限制3KB时,解决中国政府采购网附件采集问题
|
|
|
s.L.SetGlobal("downloadFile", s.L.NewFunction(func(S *lua.LState) int {
|
|
|
if s.FileLastThreeTimes == nil {
|
|
@@ -913,25 +911,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
|
|
@@ -940,8 +962,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
|
|
|
}))
|
|
@@ -1000,24 +1040,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)
|