I have a C#.NET application running on a machine. How do I calculate the checksum of the entire code at runtime?
Note:
I do not want to calculate the checksum of the image in use but the actual code part.
I have a C#.NET application running on a machine. How do I calculate the checksum of the entire code at runtime?
I do not want to calculate the checksum of the image in use but the actual code part.
In runtime you don't have access to the original written source code.
I would just use code signing, but if you really want to roll your own solution (which may be a bad idea. Code signing is a Good Thing) you could use reflection to look into the IL code and calculate a checksum based on that. That's not a very nice solution, and could cause some weird bugs, so please, save yourself some trouble and use code signing.
I have never used this, but:
Using reflection you can navigate to the GetILAsByteArray and do a checksum (per method).
But I think it will be a lot easier to use code signing or the Assembly.GetExecutingAssembly and then do a checksum on the .dll or .exe.
a strong name on your assembly does this - but you sort of have to trust that it is working as advertised. what is the precise problem you are tying to solve?