Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,

Iam using text file(.txt) to read some data into c# Dot Net.
I want to protect this file with a password.
Is it possible? Pls give me Reply asap.

Thanks

Regards
Nirmala Saravanan<b></b>
Posted

You can encrypt it (with a password).
 
Share this answer
 
Comments
Mmohmmad 8-Mar-12 6:33am    
Thanks for your answers.

If we encrypt files is it possible to crack it?
Dylan Morley 8-Mar-12 6:44am    
That totally depends how strong your encryption routine is! Have a look here though, should get you started

http://www.codeproject.com/Articles/5719/Simple-encrypting-and-decrypting-data-in-C

Note this method

public static void Encrypt(string fileIn,
string fileOut, string Password

So, give it the name of the file to be encrypted, the name of the output file & the password to use during the encryption process.
As JSOP says, you can encrypt the contents of the file. Use the password to create a DES3 key or something similar (using one of the cryptographic algorithms shipped with the framework), encrypt the content and re-save the file. Note though that if you do this, the file is essentially no longer a text file and will only be readable by your application.

There is no capability within the text format to specify a password in a similar way to ZIP files, where compliant editors will be able to prompt for it and open the file.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900