public ActionResult Index() { var h = "EsSWxhhkcqfIvh4n1K83DOQynZmnoH3XvZo1APFl6/w="; var user = "******"; var hash = EncryptionClass.EncryptPass(user); var decrypt = EncryptionClass.DecryptPass(h); //JOPsUBHAck9T8bb96DGtLg == byte[] base64HashesPassword = Convert.FromBase64String(h); string pass = EncryptionClass.DecryptRJ256(base64HashesPassword); var decrypt256 = EncryptionClass.EncryptRJ(h); //DecryptRJ256 return(View()); }
protected void Page_Load(object sender, EventArgs e) { form1.Action = System.Configuration.ConfigurationManager.AppSettings["LMS_link"].ToString(); if (Session["LogStatus"].ToString() == "0-0") { LogStatus.Value = Session["LogStatus"].ToString(); ScriptManager.RegisterStartupScript(this, GetType(), "submitform", "submitform();", true); } else { LogStatus.Value = Session["LogStatus"].ToString(); string key = "b3afc5fd20e3637160da4f9cab6c8072"; string IV = "a214ee38a470c5974c10498b7152ca39"; // string key = "b2afc5fd22e3637260da4f9cab6c8272"; // string IV = "a224ee38a470c5974c20498b7252ca39"; string userName = "", pass = ""; //یک کارمندو مدیرگروه 2- استاد 3- دانشجو 4- ممتحن switch (Session["UserType_lms"].ToString()) { case "1": if (Session[sessionNames.roleID].ToString() == "33") { userName = "******"; pass = Session["p"].ToString(); } else if (Session[sessionNames.roleID].ToString() == "32") { userName = "******"; pass = Session["p"].ToString(); } else { userName = Session[sessionNames.user_Karbar].ToString(); pass = Session["p"].ToString(); } break; case "2": userName = "******" + Session[sessionNames.userID_StudentOstad].ToString(); pass = Session["Password"].ToString(); break; case "3": userName = Session[sessionNames.userID_StudentOstad].ToString(); pass = Session["Password"].ToString(); break; case "4": userName = "******" + Session[sessionNames.user_Karbar].ToString(); pass = Session["p"].ToString(); break; } // var ddd = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss"); // string message = "970225966;1990079997;"+ddd; // //string message = "99900999;0012244511;2020-05-12 15:20:01"; // string password = "******"; // // Create sha256 hash // SHA256 mySHA256 = SHA256Managed.Create(); // byte[] key123 = mySHA256.ComputeHash(Encoding.ASCII.GetBytes(password)); // string author = "zxcvbnmasdfghjkl"; // // Convert a C# string to a byte array // //byte[] bytes = Encoding.ASCII.GetBytes(author); // // Create secret IV // byte[] iv = new byte[16] { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }; //// iv = bytes; // string encrypted = this.EncryptString(message, key123, iv); // string decrypted = this.DecryptString(encrypted, key123, iv); // var u = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss"); // var d = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); // Console.WriteLine(encrypted); // Console.WriteLine(decrypted); UserName.Value = EncryptionClass.EncryptRJ(userName, key, IV); Password.Value = EncryptionClass.EncryptRJ(pass, key, IV); ScriptManager.RegisterStartupScript(this, GetType(), "submitform", "submitform();", true); } }
//############################################# protected void btn_Save_Click(object sender, EventArgs e) { if (Page.IsValid) { if (fileUploader.HasFile) { string QExt = "pdf"; string AttExt = "jpg"; string fullPathQuestionFile = ""; string fullPathAttachFile = ""; string fullPathZipFile = ""; //helper class to transfer data to db var Q_Att_Dto = new ExamQuestionDto(); ViewState["Qs_Attach"] = null; if (AttachUploader.HasFile) { AttExt = CommonBusiness.getFileExtension(AttachUploader.FileName).ToLower(); } if ((QExt != "pdf" && QExt != "jpg") || (AttExt != "pdf" && AttExt != "jpg")) { rwm.RadAlert("فرمت صحیح انتخاب گردد", null, 100, "خطا", ""); } else { string did = Request.QueryString["did"].ToString(); var examQ = eBusiness.GetExamQuestionsbyDid(did, null, null); if (examQ != null && bool.Parse(examQ.Rows[0]["TemplateDownloaded"].ToString()) == true) { var userID = Session[sessionNames.userID_StudentOstad].ToString(); var questionID = examQ.AsEnumerable().Select(s => s.Field <int>("examQuestionID")).FirstOrDefault(); var relativePath = $"~/QueizPapers/{examQ.Rows[0]["Term"].ToString()}/{userID}/pdfFiles/{did}"; string absolutePath = Server.MapPath(relativePath); fullPathZipFile = $"{absolutePath}/{did}.zip"; string filepass = generaterandomstr(8); //Directory.GetDirectories(absolutePath).ToList().ForEach(dir => Directory.Delete(dir, true)); //Directory.GetFiles(absolutePath, "*.*").Where(w=>w.Contains("_canceled")).ToList().ForEach(file => File.Delete(file)); if (fileUploader.HasFile)//آپلود سوالات { Q_Att_Dto.IsExistQuestionFile = true; Q_Att_Dto.Did = did.ToString(); Q_Att_Dto.QuestionId = questionID.ToString(); Q_Att_Dto.UserId = userID; Q_Att_Dto.HashedPass = EncryptionClass.EncryptRJ(filepass); Q_Att_Dto.RelativePath = relativePath; QExt = CommonBusiness.getFileExtension(fileUploader.FileName).ToLower(); if (!Directory.Exists(absolutePath)) { Directory.CreateDirectory(absolutePath); } fullPathQuestionFile = $"{absolutePath}/{did.ToString()}.{QExt}"; if (QExt == "pdf" || QExt == "jpg") { //var file = fileUploader.PostedFile; var qfSaved = SaveFile(fileUploader.PostedFile, absolutePath, did.ToString() + "." + QExt); if (!qfSaved) { rwm.RadAlert("خطا در روند بارگذاری فایل سوالات! لطفا مجدداً بارگذاری نمائید.", null, 100, "", ""); return; } using (ZipFile zip = new ZipFile()) { zip.Password = filepass; FileStream stream = null; using (stream = new FileStream(fullPathQuestionFile, FileMode.Open, FileAccess.ReadWrite)) { zip.AddEntry(did.ToString() + "." + QExt, stream); zip.Save(fullPathZipFile); } } } } if (AttachUploader.HasFile)//آپلود سوالت پیوست { Q_Att_Dto.IsExistAttachFile = true; AttExt = CommonBusiness.getFileExtension(AttachUploader.FileName).ToLower(); fullPathAttachFile = $"{absolutePath}/{did.ToString()}Attached.{AttExt}"; if (AttExt == "jpg" || AttExt == "pdf") { Q_Att_Dto.AttExt = AttExt; var att_fSaved = SaveAttachFile(AttachUploader.PostedFile, absolutePath, did.ToString() + "Attached." + AttExt); if (!att_fSaved) { rwm.RadAlert("خطا در روند بارگذاری فایل پیوست سوالات! لطفا مجدداً بارگذاری نمائید.", null, 100, "", ""); return; } using (ZipFile zip = new ZipFile(fullPathZipFile)) { zip.Password = filepass; FileStream stream = null; stream = new FileStream(fullPathAttachFile, FileMode.Open, FileAccess.ReadWrite); zip.AddEntry(did.ToString() + "Attached." + AttExt, stream); zip.Save(fullPathZipFile); } } } Directory.GetFiles(absolutePath, "*.*").Where(w => !w.Contains(".zip")).ToList().ForEach(file => File.Delete(file)); if (File.Exists(fullPathZipFile)) { var whiteTape = Server.MapPath("~/University/Theme/images/whitePaper.jpg"); var questioHeaderTemplate = Server.MapPath("~/University/Theme/images/QuestionHeaderTemplate.jpg"); var examQ_Detail = eBusiness.Get_ExamdetailbyDid(did, null, null); var constQuestionFileInfo = examQ_Detail.AsEnumerable().Select(x => new ExamStudentDTO() { TypeNimsal = x.Field <string>("typeNimsal"), CourseTitle = x.Field <string>("namedars"), ProfossorFullName = x.Field <string>("osname"), ExamDate = x.Field <string>("dateexam"), ExamTime = x.Field <string>("saatexam"), KeyCode = x.Field <string>("keyCode"), ExamDuration = x.Field <string>("examTime"), Calculator = x.Field <string>("calculator"), Note = x.Field <string>("note"), LowBook = x.Field <string>("LowBook"), ClassCode = x.Field <string>("ClassCode").ToString(), Grade = x.Field <string>("magh").ToString(), Major = x.Field <string>("nameresh").ToString() }).FirstOrDefault(); eBusiness.ChangeTemplateOfQuestion(absolutePath, did.ToString(), filepass, constQuestionFileInfo, questioHeaderTemplate, whiteTape, userID); pnlMainQuestion_Att_Uploaded.Visible = false; pnl_GeneratedPdf_MergedQuestion_Att.Visible = true; var lastPdfPath = $"{Request.Url.GetLeftPart(UriPartial.Authority)}/{relativePath.Replace("~/", "")}/{userID}/{did}_Momtahen_{userID}_1.pdf?ts={DateTime.Now.Ticks}"; PdfFileSource = lastPdfPath; ViewState["Qs_Attach"] = Q_Att_Dto; //var buff = System.IO.File.ReadAllBytes(asbPathMerged_Q_Att); //string base64String = Convert.ToBase64String(buff, 0, buff.Length); //SrcMergedFile = $"data:{PdfMimeType};base64,{base64String}"; //string scrp = "function f(){showLightBox(); $find(\"" +.ClientID + "\").show(); Sys.Application.remove_load(f);}Sys.Application.add_load(f);"; //ScriptManager.RegisterStartupScript(this.Page, GetType(), ClientID, scrp, true); //ContentPlaceHolder mpContentPlaceHolder ; //mpContentPlaceHolder = (ContentPlaceHolder)Page.Master.FindControl("ContentPlaceHolder1"); //mpContentPlaceHolder.Controls.Add(widnow1); //var Encrypted_Password_File = EncryptionClass.EncryptRJ(filepass); //eBusiness.UploadExamFile(relativePath + did.ToString() + ".zip", Encrypted_Password_File, did, 2); //eBusiness.UploadAttachment(did, relativePath + did.ToString() + "Attached." + AttExt);//Address //cmnb.InsertIntoStudentLog(Session[sessionNames.userID_StudentOstad].ToString(), DateTime.Now.ToShortTimeString(), 8, 22, questionID.ToString()); //cmnb.InsertIntoStudentLog(Session[sessionNames.userID_StudentOstad].ToString(), DateTime.Now.ToShortTimeString(), 8, 21, questionID.ToString()); //eBusiness.UpdateQueizStatus(2, did, ""); //ScriptManager.RegisterStartupScript(this, GetType(), "btn_Save", "CloseModal();", true); } else { rwm.RadAlert("هیچ فایلی ارسال نشده است. لطفا مجددا فایل خود را ارسال نمایید", null, 100, "", ""); } } else { rwm.RadAlert("ابتدا فرم سوالات دانلود شود", null, 100, "خطا", ""); } } } else { rwm.RadAlert("فایل سوالات انتخاب شود ", null, 100, "خطا", ""); } } }