/
uploadadvnce.aspx.cs
232 lines (211 loc) · 8.34 KB
/
uploadadvnce.aspx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Text;
using System.Security.Cryptography;
namespace WebApplication1
{
public partial class uploadadvnce : System.Web.UI.Page
{
cumfun cls = new cumfun();
String a;
string Passphrase;
string filename;
byte[] Results;
AESK ak = new AESK();
string AESKEy;
int pid;
string skk;
protected void Page_Load(object sender, EventArgs e)
{
if (Session["sessionuserid"] == null)
{
Server.Transfer("~/login/loginpage.aspx");
Response.Redirect("~/login/loginpage.aspx");
return;
}
if (!Page.IsPostBack)
{
//cls.FillCmb("select FT_Name,FT_ID from Filetypelst ", cmbfiletype, "Select Type", cmbfiletype);
}
}
public void encryption()
{
byte[] file = new byte[FileUpload1.PostedFile.ContentLength];
FileUpload1.PostedFile.InputStream.Read(file, 0, FileUpload1.PostedFile.ContentLength);
string fileName = txtfilename.Text;
byte[] Key = Encoding.UTF8.GetBytes(LTRPRIKEY.Text);
ASCIIEncoding.ASCII.GetString(Key);
try
{
string outputFile = Path.Combine(Server.MapPath("~/uploadfiles/advance"), fileName);
FileStream fs = new FileStream(outputFile, FileMode.Create);
RijndaelManaged rmCryp = new RijndaelManaged();
CryptoStream cs = new CryptoStream(fs, rmCryp.CreateEncryptor(Key, Key), CryptoStreamMode.Write);
foreach (var data in file)
{
cs.WriteByte((byte)data);
}
cs.Close();
fs.Close();
insert();
}
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "popup",
"alert(" + ex + ");", true);
}
}
public void clearall()
{
txtcommnt.Text = "";
txtdiscptn.Text = "";
txtfilename.Text = "";
// cmbfiletype.ClearSelection();
}
public void insert()
{
try
{
Label1.Text = "";
clsjob obj = new clsjob();
obj.UP_FileName = txtfilename.Text;
obj.UP_FileTypeId = 1;// Convert.ToInt32(cmbfiletype.SelectedValue);
obj.UP_Discription = txtdiscptn.Text;
obj.UP_Comment = txtcommnt.Text;
obj.UP_PrivateKey = LTRPRIKEY.Text;
obj.UP_r_id = Convert.ToInt32(Session["sessionuserid"]);
obj.advnInsertfile();
}
catch
{
}
}
public void matadata()
{
try
{
pid = Convert.ToInt32(cls.RetVal("select Top 1 up_id from advncuploadfileslist order by up_id desc"));
string filename = (Server.MapPath("~/all/advance/") + txtfilename.Text);
string inputString = File.ReadAllText(filename);
inputString = inputString.ToLower();
string[] doc = new string[1]
{
inputString.ToString()
};
//ServiceRanking.TFIDFMeasure tf = new ServiceRanking.TFIDFMeasure(doc);
string[] stripChars = { ";", ",", ".", "-", "_", "^", "(", ")", "[", "]","'",
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "\n", "\t", "\r" };
foreach (string character in stripChars)
{
inputString = inputString.Replace(character, "");
}
List<string> wordList = inputString.Split(' ').ToList();
stpwordshndl stopwords = new stpwordshndl();
string[] stopword = stopwords.StopWordsHandler();
foreach (string word in stopword)
{
while (wordList.Contains(word))
{
wordList.Remove(word);
}
}
foreach (string word in wordList)
{
Stemming.PorterStemmer pf = new Stemming.PorterStemmer();
string ssh = pf.stemTerm(word);
skk = ssh + " " + skk;
}
List<string> wordList2 = skk.Split(' ').ToList();
Dictionary<string, int> dictionary = new Dictionary<string, int>();
foreach (string word in wordList2)
{
if (word.Length > 3)
{
if (dictionary.ContainsKey(word))
{
dictionary[word]++;
}
else
{
dictionary[word] = 1;
}
}
}
var sortedDict = (from entry in dictionary orderby entry.Value descending select entry).ToDictionary(pair => pair.Key, pair => pair.Value);
cumfun obj = new cumfun();
foreach (KeyValuePair<string, int> pair in sortedDict)
{
if (pair.Value <= 2)
{
}
else
{
obj.UpdateData("insert into matadataadvnce values('" + pair.Key + "','" + pair.Value + "','" + pid + "')");
}
}
clearall();
Label1.Visible = true;
Label1.Text = "File Uploaded Successfully.";
Label1.ForeColor = System.Drawing.Color.Green;
}
catch
{
Label1.Visible = true;
Label1.Text = "Error Please try again.";
Label1.ForeColor = System.Drawing.Color.Red;
}
}
protected void btnkey_Click(object sender, EventArgs e)
{
if (cls.IsExists("select * from advncuploadfileslist where UP_FileName='" + txtfilename.Text + "' ") == true)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "popup",
"alert('File Name Already exist. Choose A Different File Name.');", true);
txtfilename.Text = "";
return;
}
else
{
try
{
filename = txtfilename.Text;
FileUpload1.SaveAs(Server.MapPath("~/all/advance/") + filename);
Passphrase = filename;
System.Text.UTF8Encoding UTF8 = new System.Text.UTF8Encoding();
MD5CryptoServiceProvider HashProvider = new MD5CryptoServiceProvider();
byte[] TAESKey = HashProvider.ComputeHash(UTF8.GetBytes(Passphrase));
TripleDESCryptoServiceProvider TAESAlgorithm = new TripleDESCryptoServiceProvider();
TAESAlgorithm.Key = TAESKey;
TAESAlgorithm.Mode = CipherMode.ECB;
TAESAlgorithm.Padding = PaddingMode.PKCS7;
byte[] DataToEncrypt = UTF8.GetBytes(filename);
try
{
ICryptoTransform Encryptor = TAESAlgorithm.CreateEncryptor();
Results = Encryptor.TransformFinalBlock(DataToEncrypt, 0, DataToEncrypt.Length);
}
finally
{
TAESAlgorithm.Clear();
HashProvider.Clear();
AESKEy = ak.Encrypt("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
AESKEy = AESKEy.Substring(0, 16);
LTRPRIKEY.Text = AESKEy;
encryption();
matadata();
}
}
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "popup",
"alert('" + ex + "');", true);
}
}
}
}
}