Răsfoiți Sursa

新增aes、des cbc加解密方法

maxiaoshan 1 an în urmă
părinte
comite
e62d34007d
2 a modificat fișierele cu 51 adăugiri și 13 ștergeri
  1. 0 13
      src/spider/msgservice.go
  2. 51 0
      src/spider/script.go

+ 0 - 13
src/spider/msgservice.go

@@ -167,19 +167,6 @@ func processeventChromedp(p *mu.Packet) {
 			code := string(data[i*8 : (i+1)*8])
 			delete(AlldownloaderChromedp, code)
 		}
-	case int32(util.Config.Uploadevent):
-		param := map[string]interface{}{}
-		json.Unmarshal(p.GetBusinessData(), &param)
-		ret := map[string]interface{}{}
-		if param["code"] != nil {
-			b, err := UpdateSpiderByCodeState(param["code"].(string), param["state"].(string))
-			ret["b"] = b
-			ret["err"] = err
-		} else {
-			ret["b"] = false
-			ret["err"] = "code或state值不存在"
-		}
-		MsclientChromedp.WriteObj(p.From, p.Msgid, mu.EVENT_RECIVE_CALLBACK, mu.SENDTO_TYPE_P2P, ret)
 	}
 }
 

+ 51 - 0
src/spider/script.go

@@ -928,6 +928,32 @@ func (s *Script) LoadScript(site, channel, user *string, code, script_file strin
 		S.Push(lua.LString(result))
 		return 1
 	}))
+	//aes cbc模式加密
+	s.L.SetGlobal("aesEncryptCBC", s.L.NewFunction(func(S *lua.LState) int {
+		origData := S.ToString(-3)
+		key := S.ToString(-2)
+		iv := S.ToString(-1)
+		bytekey := []byte(key)
+		byteorigData := []byte(origData)
+		byteiv := []byte(iv)
+		encrypted := util.AesCBCEncrypt(byteorigData, bytekey, byteiv)
+		// 将加密后的数据和初始向量进行Base64编码
+		result := base64.StdEncoding.EncodeToString(encrypted)
+		S.Push(lua.LString(result))
+		return 1
+	}))
+	//aes cbc模式解密
+	s.L.SetGlobal("aesDecryptCBC", s.L.NewFunction(func(S *lua.LState) int {
+		origData := S.ToString(-3)
+		key := S.ToString(-2)
+		iv := S.ToString(-1)
+		bytekey := []byte(key)
+		byteiv := []byte(iv)
+		data, _ := base64.StdEncoding.DecodeString(origData)
+		result := util.AesCBCDecrypter(data, bytekey, byteiv)
+		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)
@@ -966,6 +992,31 @@ func (s *Script) LoadScript(site, channel, user *string, code, script_file strin
 		S.Push(lua.LString(result))
 		return 1
 	}))
+	//des cbc模式加密
+	s.L.SetGlobal("desEncryptCBC", s.L.NewFunction(func(S *lua.LState) int {
+		origData := S.ToString(-3)
+		key := S.ToString(-2)
+		iv := S.ToString(-1)
+		bytekey := []byte(key)
+		byteorigData := []byte(origData)
+		byteiv := []byte(iv)
+		encrypted := util.DesCBCEncrypt(byteorigData, bytekey, byteiv)
+		result := base64.StdEncoding.EncodeToString(encrypted)
+		S.Push(lua.LString(result))
+		return 1
+	}))
+	//des cbc模式解密
+	s.L.SetGlobal("desDecryptCBC", s.L.NewFunction(func(S *lua.LState) int {
+		origData := S.ToString(-3)
+		key := S.ToString(-2)
+		iv := S.ToString(-1)
+		bytekey := []byte(key)
+		byteiv := []byte(iv)
+		data, _ := base64.StdEncoding.DecodeString(origData)
+		result := util.DesCBCDecrypter(data, bytekey, byteiv)
+		S.Push(lua.LString(result))
+		return 1
+	}))
 	//rsa 公钥加密
 	s.L.SetGlobal("rsaEncrypt", s.L.NewFunction(func(S *lua.LState) int {
 		origData := S.ToString(-2)