Text File / Binary File.

  • Thread starter Thread starter I_AM_DON_AND_YOU?
  • Start date Start date
I

I_AM_DON_AND_YOU?

In my program I am using the notepad file to read/write data. I don't want
that someone should be able to delete/change the contents of that file by
opening that file in Notepad or other editor. Like there is a feature in
Word to put password to open your document. I want to do something like
that in Notepad file because I can't store the data in word file (in binary
format) because I am using stream reader/write object.

Is there any way that I read/write from my vb.net program in a text file and
still able to protect that file from end users to change its contents...
 
you can open word documents and change the contents w/n any text editor...it
looks garbled because it is in word format. you'd have to come up w/ some
similar scheme or encryption to make your file garbled as well. the contents
can still be changed but just as in word, the end result of the edit will
most like corrupt the file. you can use md5 to has the file contents based
on a key that only your application knows. and, password protected or not,
you can delete any file.

fft,

steve
 
I_AM_DON_AND_YOU,
You could use the System.Security.Cryptography.CryptoStream to read & write
an encrypted stream. This encrypted stream could be a regular text file.

The user could still open the file in Notepad, however all they will see is
random letters & numbers in a binary format.

Basically you create the CryptoStream over your FileStream. You then open
your StreamReader & StreamWriter over your CryptoStream.

Dim file As New FileStream(...)
Dim crypto As New CryptoStream(file, ...)
Dim reader as New StreamReader(crypto, ...)

Dim writer as New StreamWriter(crypto, ...)

http://msdn.microsoft.com/library/d...pguide/html/cpconencryptingdecryptingdata.asp

Just be certain to use a consistent & secure Key & IV so that you are able
to decrypt the data later.

I don't have samples handy, there is a way you could use a user supplied
password as part of the Key & IV.

Hope this helps
Jay
 
Hi Don,

One danger of any encrypted data approach is that if your users do open
the file and accidentally type something and accidentally save it (an unlikely
chain of events, perhaps, but..) then the data is kaput.

Another alternative is to store the data in a file which is hidden and
read-only. That will prevent casual and accidental tampering but not a
determined user.

And, of course, you could do both. ;-)

Regards,
Fergus
 
Back
Top