On Fri, 01 Aug 2008 12:00:29 -0700, TheLostLeaf <er**@canyondigital.com>
wrote:
I wote some code that encrypts binary files, and decrypts them, works
great. It uses the same file name, so if the file is called
mountain.jpg, it encrypts it with the same name.
I'm using Rijndael, is there a script I can write that can tell if the
file is encrypted before i try to read it into a picturebox or
something.
One way i can tell is it error on load as not a valid image, but i
want to be able to do it with all files.
You can follow a filename convention, but of course that will only work as
long as no one changes the file name.
My general approach when encoding data is to attempt to decode the data in
the deepest encoding first, and work my way back. So in your case, rather
than trying to load the data as an image, you should be trying to decrypt
it. If the decryption fails, then you know it's _not_ encrypted and so
can move on to the next likely stage (e.g. loading it as an image).
If you knew the data was only one of two formats, you could do either
attempt first. But you might as well rule out the encryption first, since
that will tell you for any file whether it's been encrypted or not.
Pete