0Pricing
Electron Desktop App Development · 课时

代码签名与公证

了解 Windows 代码签名和 macOS 公证的重要性,确保用户信任并符合安全要求

代码签名与公证 是 CoddyKit 上的免费 Electron Desktop App Development 课时。 这是第 2 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Electron Desktop App Development 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Electron Desktop App Development 课程共包含 4 节课。

本课时的部分内容尚未翻译,以英文显示。

Building Trust with Code Signing

When you distribute your Electron app, users need to trust it. Operating systems like Windows and macOS have built-in security features to protect users from malicious software.

Code signing and notarization are essential steps to prove your app's authenticity and integrity, ensuring users feel safe installing it.

What is Code Signing?

Code signing is like attaching a digital signature to your application. It uses a cryptographic certificate issued by a trusted Certificate Authority (CA).

  • Authenticity: Verifies the app comes from you, the publisher.
  • Integrity: Confirms the app hasn't been tampered with since you signed it.

If the signature is invalid or altered, the OS will warn the user.

Trust on Windows

On Windows, unsigned applications often trigger security warnings like "Windows protected your PC" (SmartScreen filter).

A valid code signature helps your app pass these checks, giving users confidence and reducing installation friction. It also allows your app to be installed without extra administrator prompts for some operations.

Signing Windows Executables

To sign your Windows Electron app, you'll need a Code Signing Certificate. This is typically a PFX file containing your private key and certificate chain.

Tools like electron-builder simplify this process by letting you specify your certificate details in the configuration.

{
  "build": {
    "win": {
      "target": "nsis",
      "signingHashAlgorithms": ["sha256"],
      "signAndEditExecutable": true
    },
    "cscKeyPassword": "your-cert-password",
    "cscInstallerPassword": "your-cert-password",
    "cscLink": "path/to/your/certificate.pfx"
  }
}

Time-Stamping Your Signature

When code signing, it's crucial to also time-stamp your signature. This ensures that even if your signing certificate expires, the signature remains valid because it was signed when the certificate was active.

Most signing tools, including electron-builder, can automatically add a time-stamp server URL to your signing process.

macOS Notarization Explained

For macOS, Apple introduced Notarization as an additional security check. It's an automated service that scans your app for malicious content and code signature issues.

Think of it as Apple giving your app a "seal of approval" before it can run smoothly on macOS Catalina and later.

Meeting Apple's Gatekeeper

macOS's security feature, Gatekeeper, blocks unsigned or unnotarized apps from running by default. Users will see a warning that the app "cannot be opened because the developer cannot be verified."

Notarization allows your app to pass Gatekeeper checks without annoying users or requiring them to bypass security settings manually.

Getting Ready for Notarization

To notarize your Electron app, you need:

  • An Apple Developer ID.
  • An app-specific password for your Apple ID.
  • Your app must be signed with a Developer ID Application certificate.
  • Hardened Runtime enabled (a security feature).

electron-builder handles most of these configurations for you.

Notarizing with electron-builder

electron-builder simplifies the notarization process. You configure your Apple ID credentials and it handles uploading your app to Apple's notarization service.

It waits for the notarization to complete and then "staples" the notarization ticket to your app bundle.

{
  "build": {
    "mac": {
      "hardenedRuntime": true,
      "gatekeeperAssess": false,
      "entitlementsInherit": "build/entitlements.mac.plist",
      "entitlements": "build/entitlements.mac.plist"
    },
    "afterSign": "electron-builder-notarize"
  }
}

Secure & Automated Signing

Always keep your signing certificates and private keys secure. Treat them like sensitive passwords.

Integrate code signing and notarization into your Continuous Integration/Continuous Deployment (CI/CD) pipeline to automate the process and ensure every build is properly signed and notarized.

Check Your Knowledge

Which statements accurately describe the purpose or requirements of code signing and macOS notarization?

Recap: Trust & Security

In this lesson, we learned about the critical role of code signing for Windows and notarization for macOS in distributing your Electron applications.

These processes build user trust, ensure app integrity, and help your app run smoothly on target operating systems by satisfying their built-in security requirements.

常见问题解答

「代码签名与公证」课时是免费的吗?

是的 — 「代码签名与公证」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Electron Desktop App Development 课程的其余内容,请升级到 CoddyKit PRO。 Electron Desktop App Development 课程共包含 4 节课。

「代码签名与公证」这节课中我会学到什么?

了解 Windows 代码签名和 macOS 公证的重要性,确保用户信任并符合安全要求 你通过在浏览器中直接运行的动手代码来练习 Electron Desktop App Development,全天候 AI 导师会在你学习这节课的过程中回答你的问题。

学习 Electron Desktop App Development 需要有经验吗?

无需任何先前经验。CoddyKit 上的 Electron Desktop App Development 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 2 节课,共 4 节。

「代码签名与公证」课时需要多长时间?

大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。

我能在这节 Electron Desktop App Development 课中编写并运行代码吗?

能。每节 Electron Desktop App Development 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。

此课程中的所有课时

  1. 跨平台打包
  2. 代码签名与公证
  3. 通过应用商店分发
  4. 使用 CI/CD 自动化发布
← 返回 Electron Desktop App Development