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
...