using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NETPCryptLib;
using System.Text;
namespace NetWebTest
{
public partial class NetTestForm : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
int izip = GetLineParam("Zip");
int ienc = GetLineParam("Enc");
int iout = GetLineParam("Out");
string strpost = GetPost(Request);
if (strpost == "") return;
string strdec = "Added-" + Encode(false, strpost, izip, ienc, iout) + "-In-WebSite";
String strenc = Encode(true, strdec, izip, ienc, iout);
Response.Write(strenc);
Response.End();
}
private string Encode(bool encode, string str, int izip, int ienc, int iout)
{
CGlobalKeys gkeys = new CGlobalKeys();
CNETPInfoFormat info = gkeys.GetInfoFormat();
byte[] btext = Encoding.ASCII.GetBytes(str);
info.NETPBuf.optPNetzip = (TNETPEnumZip)izip;
info.NETPBuf.optPNetencrypt = (TNETPEnumEncrypt)ienc;
info.NETPBuf.optPNetoutput = (TNETPEnumOutput)iout;
if (encode)
info.NETPBuf.optPNetoper = TNETPEnumOperation.TNETPOperEncode;
else
info.NETPBuf.optPNetoper = TNETPEnumOperation.TNETPOperDecode;
btext.CopyTo(info.NETPBuf.NETPbuffer, 0);
info.NETPBuf.NETPbufferlen = btext.Length;
info.OpClose();
String strres = Encoding.ASCII.GetString(info.NETPBuf.NETPbuffer, 0, info.NETPBuf.NETPbufferlen);
return strres;
}
private string GetPost(HttpRequest request)
{
System.IO.Stream body = request.InputStream;
System.Text.Encoding encoding = request.ContentEncoding;
System.IO.StreamReader reader = new System.IO.StreamReader(body, encoding);
return reader.ReadToEnd();
}
private int GetLineParam(string param)
{
if (Request.Params.Get(param) != null)
return int.Parse(Request.Params.Get(param));
else
return 0;
}
}
}