C# open an encrypted file without writing the file to the disk? - c#

I have encrypted a file with c# and gave it the extention .crypted. The file extention .crypted is associated with my program. So if i double click the file i get a password request dialog from my program. After entering the correct password my program decrypts the file and writes it unencrypted to the disk without the .crypted extention, so that i can run it. After using the file i just delete the unencrypted file and if the file was altered i use my program to reencrypt the file first. But u can easily use a file recovery program to get unauthorized access to the unencrypted file. Thats why i dont want to write unencrypted files to the disk after my program decrypts them. Is it possible to open an encrypted file without ever writing it to the disk? Like saving the unencrypted file to the ram/memory and opening it from there? I dont want to write a whole file system for that. The encrypted files should stay on NTFS or ext4. I think i need to change the code at this point:
using(CryptoStream cryptoStream = new CryptoStream(fileStream, rijndael.CreateDecryptor(), CryptoStreamMode.Read))
{
// write unencrypted file to memory and execute or something else?
}

Related

password protected Base64 string convert into pdf file without password

I have Encrypted PDF File and i have convert encypted PDF file To Base64 string. I want Base64 string convert into PDF File (Means PDF file will write without password). PDF File should open.
Encrypted Base64 string is perfectly convert into pdf file but when i am trying to open the pdf file it is asking password.
I want when file is convert into Encryted base64 to PDF File then it should open without password .File is saving on my folder.
How i can do it. with asp.net with c#.
Can’t be done.
Otherwise the mere act of emailing a password protected PDF removes the protection and I’m pretty sure the payslips I get are protected.

C# ASP.NET Retrieving file address in string

I am building a method that will build an XLS file and uploading it on user's computer.
I am using this guide:
http://csharp.net-informations.com/excel/csharp-create-excel.htm
So code that will define my destination address is:
xlWorkBook.SaveAs("C:\\Something\\csharp-Excel.xls", Excel.XlFileFormat.xlWorkbookNormal);
Now it is default, but i want to allow user to define it by him self, so as far as i understand, i need an html field, which will open common "browse window" and save file path to string, which will be later used in xlWorkBook.SaveAs function. I have read a bit about FileUpload, but i don't really sure that it is what i am looking for.
The code that you have there will save the file on the web server itself, not on the user's computer. You'll need to stream the file down to the user via the browser, and then they will be able to choose where to save it.
You could save the file on the server and then stream it to the user using Response.WriteFile, or you could stream it from memory if you don't want to keep a copy of the file on the server.
This code will create a file on the server, not on the users/clients computer. If you want the user to be able to download the file to his/her computer and select the location where the file is stored, you need to create a file (.aspx file or controller method, depending on wether you are using webforms or MVC) and have it stream the file to the user's browser. The browser will then take care of displaying the "Save as" dialog where the user can select the destination location.

C# - Accessing a DBF file in a Stream

I have a WebMethod which I use to allow a user to upload a database file (*.DBF). I know I can access the *.DBF file using a OleDbConnection with the appropriate connection string. But I dont really want to save the file on the server, my WebMethod has the file contents in a stream. Is there anyway I can access the *.DBF file while it is in the stream ?

Could not decrypt file. Read Excel protected file

I have excel file and it gives error "Could not decrypt file.". When I open excel file it is opening and not prompt me for any password.
But when I check its protection from toolbar in excel. It shows file is protected.
How can I read that file using OLEDBConnection.
I had a user with this issue today... I just told her to either unprotect the worksheet
In my specific case, she actually wasn't able to unprotect the worksheet since it required a password to unprotect it, so I just had her copy/paste the data into a new Excel file instead.

Encrypting contents of a file when uploading

Am using asp.net's FileUpload control to upload a word file to the server.
I want to encrypt the contents of this file (using our custom encryption API) and then save it in the server.
How do i achieve this?what should be my approach?
Thanks.
Whatever you do on the server side, do realize that while the data is transfering over the wire, it will not be encrypted with your custom api. You will need to upload the file using an ssl connection in order ensure the data transfer is secure.
if you have your own custom encryption API, you should use it to encrypt in a temporary file and then upload the temporary encrypted result, and delete it after upload complete.
The FileUpload control gives you a handle to the file. Read the data from the file stream, encrypt it and write it to a FileStream. If the encryption process is CPU intensive and/or takes a lot of time, save the file in a temp directory and start a new thread that reads the file, encrypts its contents, saves it to a new file and deletes the temp file.
maybe u should write your own encryptor as an app and then decrypt that file on the server
this article could help u : file encrypt / decrypt

Categories