public ActionResult Upload(FileModel model) { try { if (model.PostedFile.ContentLength > 0) { var tripleDesEncryptor = new TripleDESEncrypt(model.Key); var file = new File(System.Web.HttpContext.Current); var encryptedFileContent = ""; using (var sr = new StreamReader(model.PostedFile.InputStream)) { encryptedFileContent = sr.ReadToEnd(); } var decryptedValue = tripleDesEncryptor.Decrypt(encryptedFileContent); file.SetFileContent(decryptedValue); } return View("Index"); } catch (Exception) { ViewBag.Erro = "Esta chave é inválida"; return View("Index"); } }
public ActionResult Upload(FileModel model) { try { if (model.PostedFile.ContentLength > 0) { var tripleDesEncryptor = new TripleDESEncrypt(model.Key); var file = new File(System.Web.HttpContext.Current); var encryptedFileContent = ""; using (var sr = new StreamReader(model.PostedFile.InputStream)) { encryptedFileContent = sr.ReadToEnd(); } var decryptedValue = tripleDesEncryptor.Decrypt(encryptedFileContent); file.SetFileContent(decryptedValue); } return(View("Index")); } catch (Exception) { ViewBag.Erro = "Esta chave é inválida"; return(View("Index")); } }
public ActionResult Download(string key) { var file = new File(System.Web.HttpContext.Current); var tripleDesEncryptor = new TripleDESEncrypt(key); var content = file.GetFileContent(); var encryptedContent = tripleDesEncryptor.Encrypt(content); ViewBag.GeneratedPassword = key; return(File(Encoding.UTF8.GetBytes(encryptedContent), "text/plain", "encryptedPassword.txt")); }
public ActionResult Download(string key) { var file = new File(System.Web.HttpContext.Current); var tripleDesEncryptor = new TripleDESEncrypt(key); var content = file.GetFileContent(); var encryptedContent = tripleDesEncryptor.Encrypt(content); ViewBag.GeneratedPassword = key; return File(Encoding.UTF8.GetBytes(encryptedContent), "text/plain", "encryptedPassword.txt"); }