static private DecryptString ( Array, cipherText, Array, Key, Array, IV ) : string | ||
cipherText | Array, | |
Key | Array, | |
IV | Array, | |
Résultat | string |
public IActionResult Save(Product product) { var imgFile = HttpContext.Request.Form.Files[0]; string dirPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "Upload"); string file = Path.Combine(dirPath, imgFile.FileName); if (!Directory.Exists(dirPath)) { Directory.CreateDirectory(dirPath); } if (System.IO.File.Exists(file)) { System.IO.File.Delete(file); } using (FileStream stream = new FileStream(file, FileMode.CreateNew, FileAccess.Write)) { imgFile.CopyTo(stream); } Product data = product; data.CatalogId = EncryptHelper.DecryptString(product.CatalogId); data.CatalogName = product.GetCatalog().SingleOrDefault(p => p.Id == new Guid(data.CatalogId)).Name; data.Img = Path.GetFileName(imgFile.FileName); productOperation.Create(data); return(Redirect("Index")); }
/// <summary> /// 判断手机用户是否登录,根据页面URL中sid参数判断 /// </summary> /// <param name="key"></param> /// <returns></returns> public static Boolean CheckUserIsLogin(String key) { if (String.IsNullOrEmpty(key)) { return(false); } try { String s = EncryptHelper.DecryptString(key); if (!(s.IndexOf(":") > 0)) { return(false); } String[] arrs = s.Split(':'); if (arrs.Length == 2 && arrs[0].Length > 0 && arrs[1] == "true") { return(true); } else { return(false); } } catch { return(false); } }
/// <summary> /// 取得登录用户ID /// </summary> /// <param name="key"></param> /// <returns></returns> public static String GetUserID(String key) { if (String.IsNullOrEmpty(key)) { return("0"); } try { String s = EncryptHelper.DecryptString(key); if (!(s.IndexOf(":") > 0)) { return("0"); } String[] arrs = s.Split(':'); if (arrs.Length == 2 && arrs[0].Length > 0 && arrs[1] == "true") { return(arrs[0]); } else { return("0"); } } catch { return("0"); } }
public IActionResult SaveDetail(string item, string price, string val) { Response resp = new Response(); if (string.IsNullOrEmpty(item) || string.IsNullOrEmpty(price)) { resp.Code = -1; resp.Content = new ArgumentNullException().Message; return(Json(resp)); } user = new UserHelper((ClaimsIdentity)User.Identity); OrderDetail detail = new OrderDetail(); detail.Price = int.Parse(price); detail.Item = item; detail.UserId = new Guid(EncryptHelper.DecryptString(user.GetUserId())); detail.UserName = user.GetUserName(); detail.OrderId = new Guid(EncryptHelper.DecryptString(val)); orderDetailOperation.Create(detail); resp.Code = 1; return(Json(resp)); }
public IActionResult GetProductCatalog(string CatalogId) { if (string.IsNullOrEmpty(CatalogId)) { return(Json(productOperation.GetEmptyList())); } string productId = EncryptHelper.DecryptString(CatalogId); return(Json(productOperation.GetProductByCatalog(productId))); }
public static T LoadDataWithEncrypt <T>(string path) { var newPath = Path.Combine(Application.persistentDataPath, path); using (StreamReader streamReader = File.OpenText(newPath)) { string jsonString = streamReader.ReadToEnd(); var s = EncryptHelper.DecryptString(jsonString); return(JsonUtility.FromJson <T>(s)); } }
public IActionResult Save(Order order) { string tmpId = EncryptHelper.DecryptString(order.PName); order.OrderNo = orderOperation.GetMaxNo(); order.PName = productOperation.GetById(tmpId).Name; order.PId = new Guid(tmpId); orderOperation.Create(order); return(RedirectToAction("Index")); }
public IActionResult Update(string key) { Response response = new Response(); OrderDetail detail = new OrderDetail(); detail.Id = new Guid(EncryptHelper.DecryptString(key)); detail.IsEnable = 0; orderDetailOperation.UpdateIsEnable(detail); response.Code = 1; return(Json(response)); }
public static List <T> LoadListDataWithDecrypt <T>(string path, List <T> defaultValue) { var newPath = Path.Combine(Application.persistentDataPath, path); if (File.Exists(newPath)) { using (StreamReader streamReader = File.OpenText(newPath)) { string jsonString = streamReader.ReadToEnd(); var decode = EncryptHelper.DecryptString(jsonString); return(JsonHelper.FromJson <T>(decode)); } } else { SaveListData(defaultValue, path); return(new List <T>()); } }
public IActionResult Payment(string token) { try { EncryptHelper EncryptHelper = new EncryptHelper(CommonConst.API_ENCRYPT_KEY); token = token.Replace(" ", "+"); string dataDecrypt = EncryptHelper.DecryptString(token); var rescoure = JsonConvert.DeserializeObject <SubmitForm>(dataDecrypt); Transactions trans = new Transactions() { ID = Guid.NewGuid(), OrderId = rescoure.OrderId, CreatedDate = DateTime.Now, OrderAmount = rescoure.Amount, Description = rescoure.Decription, PaymentMethod = rescoure.PaymentMethod, BackUrl = rescoure.BackUrl, Currency = rescoure.Currency, }; var response = RestAPI.SendPostRequest("api/Transaction/RequestPayment", trans); dynamic jsonDeserialize = JsonConvert.DeserializeObject(response.Content); if (jsonDeserialize.statusCode.ToString() == "2" || jsonDeserialize.statusCode.ToString() == "0") { return(Redirect($"{trans.BackUrl}?status={jsonDeserialize.message.ToString()}&errorCode=2")); } else { return(View("Index", trans)); } } catch (Exception ex) { var ErrorViewModel = new ErrorViewModel() { RequestId = "Error Submit", }; return(View("Error", ErrorViewModel)); } }
/// <summary> /// Send an email using gmail /// </summary> /// <param name="Email"></param> /// <returns></returns> public static bool SendMail(Email Email) { bool result = false; try { Email SavedEmail = Email; MailAddress fromAddress = new MailAddress(Email.FromEmail, MailName); MailAddress toAddress = new MailAddress(Email.ToEmail, "To " + Email.ToEmail); string fromPassword = EncryptHelper.DecryptString(PasswordMailAdress); if (String.IsNullOrWhiteSpace(Email.EndMailTemplate)) { Email.EndMailTemplate = "_EndMail_" + CommonsConst.Languages.ToString(Email.LanguageId); } if (!String.IsNullOrWhiteSpace(Email.EMailTemplate) && !String.IsNullOrWhiteSpace(Email.ToEmail)) { string TemplateName = Email.EMailTemplate; Email.Subject = "#WebsiteTitle# - " + Email.Subject; var smtp = new SmtpClient { Host = "smtp.gmail.com", Port = 587, EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new NetworkCredential(fromAddress.Address, fromPassword) }; smtp.SendCompleted += new SendCompletedEventHandler(SendCompletedCallback); string PathHeaderOnServer = Email.BasePathFile + "\\_HeaderMail.html"; string PathFooterOnServer = Email.BasePathFile + "\\_FooterMail.html"; string PathEndMailOnServer = Email.BasePathFile + "\\" + Email.EndMailTemplate + ".html"; string PathTemplateOnServer = Email.BasePathFile + "\\" + TemplateName + ".html"; string headerTemplate = new StreamReader(PathHeaderOnServer).ReadToEnd(); string bodyTemplate = new StreamReader(PathTemplateOnServer).ReadToEnd(); string footerTemplate = new StreamReader(PathFooterOnServer).ReadToEnd(); string endMailTemplate = new StreamReader(PathEndMailOnServer).ReadToEnd(); bodyTemplate = headerTemplate + bodyTemplate + endMailTemplate + footerTemplate; // bodyTemplate= new StreamReader(Email.BasePathFile + "/_Test.html").ReadToEnd(); foreach (var content in Email.EmailContent) { string key = content.Item1; string value = content.Item2; if (key.Contains("_watcher")) { value = AddEmailWatcher(value, Email.AuditGuidId); } bodyTemplate = bodyTemplate.Replace(key, value); Email.Subject = Email.Subject.Replace(key, value); } List <Tuple <string, string> > GenericEmailContent = GetGenericEmailContent(); foreach (var content in GenericEmailContent) { bodyTemplate = bodyTemplate.Replace(content.Item1, content.Item2); Email.Subject = Email.Subject.Replace(content.Item1, content.Item2); } var message = new MailMessage(fromAddress, toAddress) { Subject = Email.Subject, Body = bodyTemplate, IsBodyHtml = true }; if (Email.AttachmentsMails != null) { foreach (System.Net.Mail.Attachment file in Email.AttachmentsMails) { if (file != null) { try { message.Attachments.Add(file); } catch (Exception e) { Commons.Logger.GenerateError(e, System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "file = " + file + " and UserMail = " + Email.ToEmail + " and subject = " + Email.Subject); } } } } if (Email.CCList != null) { foreach (string CC in Email.CCList) { message.CC.Add(CC); } } smtp.SendAsync(message, SavedEmail); result = true; } } catch (Exception e) { result = false; Commons.Logger.GenerateError(e, System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "UserMail = " + Email.ToEmail + " and subject = " + Email.Subject + " and EMailTypeId = " + Email.EMailTypeId); } return(result); }