如何使用 NSIS 对文件进行签名?

How can I sign the files using NSIS?

如何使用 NSIS 对文件进行签名?

我们将 WIX 安装程序更改为 NSIS。

在 WIX 安装程序的早期,它在 .xml 文件中使用如下所示来对文件进行签名。

<property name="FileSigningDrive" location="${env.FILE_SIGNING}"/>

        <!--echo message="Signing Setup.exe ....." />
        <exec dir="${FileSigningDrive}\" 
              executable="${FileSigningDrive}\signcode.exe" failonerror="true">
          <arg value='-spc' />
          <arg value='mycredentials.spc' />
          <arg value='-v' />
          <arg value='testkey.pvk' />
          <arg value='-t' />
          <arg value='http://timestamp.verisign.com/scripts/timpstamp.dll' />
          <arg value='"${install}\RootCDDir\setup.exe"'  />
        </exec-->

同样,如何在NSIS中对文件进行签名?

您可以通过使用 !finalize:

执行您选择的命令来签署安装程序
!finalize 'signcode -t http://example.com/timestamp "%1"' = 0 ; %1 is replaced by the install exe to be signed.

卸载程序签名有点烦人,需要您generate the uninstaller and then signing it

这是对@Anders 回答的更新。

从 v3.08 开始,您可以直接使用 !uninstfinalize 对卸载程序进行签名。

所以现在您可以像这样编写代码了。

!finalize 'signcode -t http://example.com/timestamp "%1"' = 0 ; %1 is replaced by the install exe to be signed.
!uninstfinalize 'signcode -t http://example.com/timestamp "%1"' = 0 ; %1 is replaced by the uninstaller exe to be signed.

请记住,您必须在 !finalize!uninstfinalize 处附加 = 0。这将同时停止 运行ning 两者。否则,signtool.exe 将失败,因为它不能 运行 并行。