public FileStreamResult Download(string fileName) { var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName); var stream = DEncrypt4ImageHelper.DecryptFile(path, "helloworld"); stream.Seek(0, SeekOrigin.Begin); return(new FileStreamResult(stream, "application/jpg") { FileDownloadName = fileName }); }
static void Main(string[] args) { Console.BackgroundColor = ConsoleColor.Red;; DEncrypt4ImageHelper.EncryptFile(@"format-indent-less.png", @"format-indent-less.img", "helloworld"); Console.WriteLine("Find the encrypt file in debug folder"); DEncrypt4ImageHelper.DecryptFile(@"format-indent-less.img", @"format-indent-less.png", "helloworld"); Console.Write("decrypt file as stream and save it as original format!"); }
public ActionResult Index(HttpPostedFileBase file) { if (file.ContentLength > 0) { var fileName = Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName); var fileEncryptStream = DEncrypt4ImageHelper.EncryptFile(file.InputStream, "helloworld"); var fs = System.IO.File.OpenWrite(path); foreach (byte b in fileEncryptStream.ToArray()) { fs.WriteByte(b); } fs.Close(); fileEncryptStream.Close(); } return(RedirectToAction("Index")); }