PDA

View Full Version : How to detect succesful decryption.


longedge
02-03-2008, 08:44 AM
I'm working on a project to provide users with a quick and easy way to encrypt and decrypt a folder of files for use 'off-site' but I realised that the decryption process doesn't in itself provide any way to check for a successful decryption. If the password is incorrect the process goes ahead and produces 'rubbish'.

At the moment I'm putting a check file in to the files waiting for encryption which gets encrypted along with the rest. After decryption I'm reading it back to a string and displaying the string in a label. The label either reads "Success" or "öÖßͽU)â-Q§pÂïôÚƒ" so it's obvious whether it has worked or not :lol

To say the least, it's not very elegant. Does anybody know of a better way to do it?

Lorne
02-05-2008, 11:37 AM
Perform a checksum calculation on the file and compare the result to a predetermined correct value.

You can use either Crypto.MD5DigestFromFile or File.GetCRC to calculate the checksum.

longedge
02-05-2008, 11:43 AM
Thanks for that Lorne.