How to programmatically verify an assembly is signed with a specific Certificate?

后端 未结 4 1746
时光说笑
时光说笑 2021-02-02 12:39

My scenario is we have one program (exe) that will start other programs if found in a particular folder. I want to ensure it only ever starts programs which are signed with our

4条回答
  •  抹茶落季
    2021-02-02 13:04

    Here's a blog post with code samples on how to verify assembly signatures:
    http://blogs.msdn.com/b/shawnfa/archive/2004/06/07/150378.aspx

    The code sample at the end shows how to verify if an assembly was signed by Microsoft or not - you can do the same by getting the certificate token for your company's certificate(s).

    Update: user @Saber edited this with the following update, but that update was rejected by others. However, it is very valid advice, so I am reposting his/her edit since SO won't let me approve it:

    Edit (thank you, OP): If you want to do this more securely (i.e. make your program more tamper-proof), reference an assembly in your program which is strongly named with the relevant key, then use the token of the referenced assembly to compare with the token of the calling assembly. If you use a byte arrays (as per the link), it can simply be hex edited and changed.

提交回复
热议问题