0
I’m doing a feature on a system where; Any sector will upload an important file, this file contains sensitive information linked to each employee of the company. Each employee can open his own file, but no other can open it.
The file is in PDF format, and all follow a rule of ex nomenclature:
ano-mes-codigofuncionario.pdf
.
What happens... when I allow the employee to download your file, he will see the name and if he understands the logic of the names, he may change the employee code and view other people’s files.
I would then like, at the time of saving the file to disk, to generate a hash based on the file name policies and when I need to identify the file to designate each employee I could "decrypt" and take the original name.
The end result should look something like: fe415d322sefe185d32sd1f51000e1fea6e.pdf
, this way it will be more difficult for other employees to try to view other files.
Here I saved on disk:
private void SalvarArquivo(HttpPostedFile file)
{
var pathString = DiretorioTemp();
var fileName1 = Path.GetFileName(file.FileName);
bool isExists = Directory.Exists(pathString);
if (!isExists)
Directory.CreateDirectory(pathString);
var path = string.Format("{0}\\{1}", pathString, file.FileName);
file.SaveAs(path);
}
After reading the file I click the button for the user, respecting the rules that are used to name the original file.
public static void Download(string fName)
{
FileInfo fInfo = new FileInfo(fName);
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = "application/octet-stream";
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=\"" + fInfo.Name + "\"");
HttpContext.Current.Response.AddHeader("Content-Length", fInfo.Length.ToString());
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.WriteFile(fInfo.FullName);
fInfo = null;
}
Note: If I generate a hash and cannot undo it will not help, because I do not know the parameters used on the date the files were inserted.
Remembering that, windows does not allow some characters(* / \ < >) for this reason I would like something that is simple.
This information is not saved in the bank?
– Jéf Bueno
I’m not saving in the bank.
– Thiago Araújo
Then the way is to save with the original name and change the name when downloading. You can ask the question the code that downloads the file?
– Jéf Bueno
You download with
Process.Start
???– Jéf Bueno
This, I just search the file and play for it on the screen (to print)
– Thiago Araújo
This isn’t ASP.NET, right?
– Jéf Bueno
I’m using Process.Start just to take the test to return the file, the problem I have is to inhibit the name so that it does not find. It is Asp.net
– Thiago Araújo
I’m not sure I understand. At the end of it all you’ll need to do the download file, right? Via ASP.NET MVC, right?
– Jéf Bueno
This project is still in Asp.net Webforms and yes, the end result is to make the file download available.
– Thiago Araújo
Right. I don’t know about Webforms. You can ask the question the code you use to do download?
– Jéf Bueno