I'm using the following code:
AppDomain.CurrentDomain.AssemblyLoad += (sender, args) =>
{
var token = args.LoadedAssembly.GetName().GetPublicKeyToken();
if (!IsValidToken(token))
{
Process.GetCurrentProcess().Kill();
}
};
Where IsValidToken()
compares the public key token of the assembly being loaded against a list of authorized public key tokens hardcoded in my application as byte arrays.
Is this a good security measure to prevent code injection attacks? Also, is this necessary given the fact that I will later obfuscate my application using NetReactor? I'm trying to prevent any "snooping" into my application, not only coming from the Snoop tool, but from any external undesired sources as well.