使用SignTool.exe对文件进行数字签名

SignTool.exe是微软官方发布的一个命令行工具,用于对文件进行数字签名,以及验证文件和时间戳文件中的签名,微软官方介绍文档:https://docs.microsoft.com/zh-cn/dotnet/framework/tools/signtool-exe

此工具会自动随 Visual Studio 一起安装,如果你的电脑已经安装了Visual Studio,那么你可能在以下目录找到它:

C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Bin\signtool.exe
C:\Program Files\Microsoft SDKs\Windows\v7.1A\Bin\signtool.exe

该工具只能在DOS命令行运行,没有图形界面。

使用SignTool.exe对文件进行数字签名时需要使用*.pfx格式的证书

1.对exe程序数字签名

# /p <passwd>  表示pfx证书的打开密码
signtool sign /f MyCert.pfx /p MyPassword MyFile.exe

2.对dll文件数字签名

signtool sign /f MyCert.pfx /p MyPassword MyFile.dll

3.数字签名并加盖时间戳

signtool sign /f MyCert.pfx /t http://timestamp.digicert.com MyFile.exe

4.对已签名的exe程序加盖时间戳,如果exe程序没有签名则不能加盖时间戳。

signtool timestamp /t http://timestamp.digicert.com MyFile.exe

5.将*.crt格式证书转换成*.pfx格式

# 格式转换需要两个文件:私钥(xxxx.key)和证书(xxxx.crt)
# 转换证书格式时OpenSSL会要求你设置pfx证书的打开密码,你可以直接按回车键不设置密码。
openssl pkcs12 -export –in xxxx.crt -inkey xxxx.key -out xxxx.pfx

...

猜你喜欢

转载自www.cnblogs.com/dgjnszf/p/12332498.html