Please see my comment. First question needs clarification, but you can answer it yourself if you read on the rest.
First of all, please see:
http://en.wikipedia.org/wiki/Cryptographic_hash_function[
^],
http://en.wikipedia.org/wiki/Sha2[
^].
If should explain you what happens if you calculate SHA265 of anything.
About C# programming of hash, everything is already implemented for you in .NET FCL. Please see:
http://msdn.microsoft.com/en-us/library/system.security.cryptography.hashalgorithm.aspx[
^].
Now, infected files. You don't "convert" anything, you just calculate the hash of data.
No, you cannot use the cryptographic hash function
of the whole file to detect viruses. If you read about the properties of cryptographic hash functions, you will clearly see it. The function is used for different purposes: it can help to detect that some executable files have been changed. If you store the hash functions of some set of executable files and check up on regular basis that newly calculated hash function is the same as the stored value, you can have a pretty good guarantee that the files were not changed. The only legitimate reason for an executable file to change should be its upgrade or rebuild.
It's infeasible to modify a file and its hash function in a consistent manner to cheat such system, due to the same properties of the cryptographic hash function. A similar but more powerful approach is using
digital signatures on executable files, based on a very different technology,
public-key cryptography. Please see:
http://en.wikipedia.org/wiki/Digital_signature[
^],
http://en.wikipedia.org/wiki/Public-key_cryptography[
^].
Among other things, it makes the files self-protected.
Hash functions are actually used for detecting viruses by comparing, but it has nothing to do with what you tried to suggest. However, the approach based on the database of know virus signatures, is not serious enough. You can consider it only as a first line of defense. It can detect the simplest viruses quickly, that's it. "Serious" viruses are polymorphic/metamorphic:
http://en.wikipedia.org/wiki/Computer_virus[
^].
Digging into the complex field of virus detection would be a huge overkill, well beyond the normal format of this forum, and, I guess, beyond your goals.
—SA