开发者

Determining hash of my own application as it is run?

开发者 https://www.devze.com 2023-02-01 10:51 出处:网络
I want my C# Windows executable to determine its own HASH value. I know how to implement Hash, but how to 开发者_开发知识库determine at run-time?Not sure if by hash you mean the public key token, or y

I want my C# Windows executable to determine its own HASH value. I know how to implement Hash, but how to 开发者_开发知识库determine at run-time?


Not sure if by hash you mean the public key token, or your own hashing algorithm.

With these you can simply get the public key token property from the assembly object:

System.Reflection.Assembly.GetExecutingAssembly(); // Assembly reference
System.Reflection.Assembly.GetEntryAssembly(); // Top level assembly reference

With this you can use your own hashing algorithm:

System.Reflection.Assembly.GetExecutingAssembly().Location // Filename


Assembly.GetExecutingAssembly().Location is the path to your executable. You can read it and compute it's hash with SHA1CryptoServiceProvider or something.

0

精彩评论

暂无评论...
验证码 换一张
取 消