public string Post_retbyte2(string URL, string refer, string postingdata) { byte[] arrOutput = Post_retbyte(URL, refer, postingdata); byte[] arrDescrypt = ZlibCompress.DecompressBytes(arrOutput); string outputstr = System.Text.Encoding.UTF8.GetString(arrDescrypt); return(outputstr); }
public string DownloadBytearr2(string URL, string refer, bool newCookie) { byte[] arrOutput = DownloadBytearr(URL, string.Empty, false); byte[] arrDescrypt = ZlibCompress.DecompressBytes(arrOutput); string outputstr = System.Text.Encoding.UTF8.GetString(arrDescrypt); return(outputstr); }
public static string GetDeBase64ZipEncry(string sEnStr) { byte[] bpath = Convert.FromBase64String(sEnStr); bpath = ZlibCompress.DecompressBytes(bpath); string sDeStr = Encoding.Default.GetString(bpath, 0, bpath.Length); DelphiDes des = new DelphiDes(); return(des.DecryStrHex(sDeStr, "uto@+~9%")); }
public bool SendByteArr(byte[] bytearr, ref string retstr) { try { NetworkStream ns = m_tcpClient.GetStream(); if (ns.CanWrite) { ns.Write(bytearr, 0, bytearr.Length); ns.Flush(); byte[] recvarr = ReceiveByteArray(ns); // 获取待解码字节流 int nPos = 4 + 32 + 4;//起始位置 int nTotalLen = (int)(recvarr[0] << 24) + (int)(recvarr[1] << 16) + (int)(recvarr[2] << 8) + (int)(recvarr[3]); int nLen = nTotalLen - 32 - 4; byte[] outputarr = new byte[nLen]; Array.Copy(recvarr, nPos, outputarr, 0, nLen); // 解码 byte[] arrDescrypt = ZlibCompress.DecompressBytes(outputarr); string outputstr = System.Text.Encoding.UTF8.GetString(arrDescrypt); retstr = outputstr; } else { Console.WriteLine("不能写入数据流"); //Console.WriteLine("You cannot write data to this stream."); m_tcpClient.Close(); // Closing the tcpClient instance does not close the network stream. ns.Close(); return(false); } return(true); } catch (Exception ex) { Console.WriteLine("转发数据失败,Reason=" + ex.Message); } return(false); }
public static List <KeyValuePair <string, string> > getZipByteArr(byte[] recvarr) { List <KeyValuePair <string, string> > lst = new List <KeyValuePair <string, string> >(); int index = 0; try { while (index != -1) { int nPos = 4 + 32 + 4 + index;//起始位置 int nTotalLen = (int)(recvarr[index + 0] << 24) + (int)(recvarr[index + 1] << 16) + (int)(recvarr[index + 2] << 8) + (int)(recvarr[index + 3]); int nLen = nTotalLen - 32 - 4; if (nLen > recvarr.Length - index) {// 格式不正确的报文不解析 byte[] temparr = new byte[recvarr.Length - index]; Array.Copy(recvarr, index, temparr, 0, recvarr.Length - index); // 打印 出错字符串 string str = byteToHexStr(temparr); System.Text.ASCIIEncoding encoder = new System.Text.ASCIIEncoding(); //String StringMessage = encoder.GetString(recvarr, index, 40); ConsoleLog.Instance.writeInformationLog("无法解析的报文,字节数组=" + str + ";iindex=" + index); return(lst); } else if (nLen < 0) { break; } byte[] outputarr = new byte[nLen]; Array.Copy(recvarr, nPos, outputarr, 0, nLen); byte[] cmd = new byte[32]; Array.Copy(recvarr, index + 4, cmd, 0, 32); string cmdstr = System.Text.Encoding.Default.GetString(cmd).TrimEnd('\0'); // 将字节流解析为字符串 byte[] arrDescrypt = ZlibCompress.DecompressBytes(outputarr); if (arrDescrypt != null) { string outputstr = System.Text.Encoding.UTF8.GetString(arrDescrypt); lst.Add(new KeyValuePair <string, string>(cmdstr, outputstr)); } if (index + nTotalLen + 4 < recvarr.Length) { index += nTotalLen + 4; } else { index = -1; } } } catch (Exception ex) { // 打印 出错字符串 string str = byteToHexStr(recvarr); ConsoleLog.Instance.writeInformationLog("解析时发生异常,字节数组=" + str + ";index=" + index); Console.WriteLine(ex.Message); } return(lst); }