如何使用 electron builder 登录 windows 安装程序

How to sign in windows installer using electron builder

我正在为 windows 配置 package.json。包装器工作正常。但是,我也想签署我的 windows 安装程序文件但无法执行。

我已经完成了本教程 WindowsConfiguration 并得到了这一行:

sign String | (configuration: CustomWindowsSignTaskConfiguration) => Promise - The custom function (or path to file or module id) to sign Windows executable.

问题是,我不知道如何为 windows 安装程序签名创建 JS 文件以及我必须为其配置使用哪些参数。谢谢你的时间。

使用 electron-builder,您唯一需要签署您的 Windows 应用程序的是设置这两个环境变量 CSC_LINKCSC_KEY_PASSWORD,如下所述:https://www.electron.build/code-signing.

--备选方案--

您可以通过在您的 package.json 中这样设置(但不推荐)来实现同样的效果:

"build": {
  ...
  "win": {
    ...
    "certificateFile": "path to your cert",
    "certificatePassword": "the password of your cert"
  }
}

希望这对您有所帮助。

您可以创建自己的签名工具来签署您需要的内容。

首先,您需要 signtool.exe 来自 Microsoft:https://docs.microsoft.com/en-us/dotnet/framework/tools/signtool-exe

然后调用child_process.exec为您的文件签名,例如:

exec(`call "${PATH_TO_SIGNTOOL_EXE}" sign /f "${KEY_SHA256}" /p ${PASS_KEY_SHA256} /fd sha256 /tr "http://sha256timestamp.ws.symantec.com/sha256/timestamp" /td sha256 /as /v "${FILE_TO_SIGN}"`)