How to Sign Software Without Exposing the Private Key

Protect your code signing identity by keeping private key material inside a secure signing environment while authorized people and release pipelines request signatures.

Core principle: Protect both the private key and the authority to use it. A non exportable key is not enough if an unauthorized workflow can still request signatures.

A safer signing workflow

01
Build and testPrepare the approved release artifact in the build environment
02
Authenticate requestConfirm the identity and permissions of the person or pipeline
03
Sign inside protected storageAn HSM or managed signing service uses the key internally
04
Verify and publishTimestamp and verify the signed artifact before release

How Can You Sign Software Without Exposing the Private Key?

The private key remains inside a protected cryptographic environment while the signing operation takes place. An authorized signing tool submits a digest or signing request, and the environment uses the key internally to create the signature. The key itself is not exported as a file or copied into the build environment.

The exact setup depends on the certificate, operating system, signing tool and key storage method. A protected key alone does not guarantee a secure release. An attacker who gains permission to invoke the signing service may still be able to sign unauthorized software.

Keep this distinction in mind: Key protection prevents or reduces exposure of key material. Signing access controls help prevent misuse of the key through an otherwise legitimate signing operation.

What Can Happen If a Code Signing Private Key Is Exposed?

A code signing private key is a high value security asset. If it is stolen or misused, an attacker may sign malicious software that appears to come from the legitimate publisher.

Exposure riskPotential consequence
Key stored in source codeAnyone with repository access may obtain it.
Key saved in a build directoryTemporary files or artifacts may leak it.
Exportable key placed in CI/CD variablesPipeline access or misconfiguration may expose it.
Shared signing credentialsUnauthorized users or jobs may sign software.
Unrestricted signing endpointCompromised workloads may request malicious signatures.
No signing audit trailSuspicious signing activity may go undetected.

A secure design protects the private key and carefully controls every identity or workload that can request a signature.

Which Methods Keep a Code Signing Private Key Protected?

Use a Hardware Security Module

A hardware security module (HSM) is a dedicated cryptographic system that generates, stores and uses private keys within a protected environment. Properly configured HSMs can prevent private key extraction while allowing authorized signing operations.

Best suited for: Enterprise software teams, regulated environments, high value signing keys and organizations that need control over key management.

Before deployment, confirm that the HSM meets the certificate authority's applicable key protection requirements and supports your signing tools and algorithms.

Use a Managed Cloud Signing Service

Cloud signing services allow authorized users and automated workflows to sign software without downloading an exportable private key. Depending on the service, the key may reside in a provider managed HSM, with requests submitted through an authenticated API, command line client or supported integration.

Best suited for: Distributed development teams, automated releases and organizations that want to avoid maintaining their own signing infrastructure.

Check key custody, request authentication, signing limits, audit records and governance controls. Products do not all offer the same protections.

Use a Dedicated Signing Server

A dedicated signing server separates code signing from the ordinary build environment. Build agents submit approved artifacts or signing requests, and the signing system applies the signature using a protected key.

Best suited for: Organizations with established release infrastructure that need a centralized signing process.

The server should validate callers, enforce release policies and record each operation. A dedicated server does not automatically protect an exportable key, so use an HSM or another approved cryptographic system where possible.

Use a Protected Local Hardware Token

Some code signing certificates are issued with a hardware token or require a compatible cryptographic device. The private key stays on the device while signing software requests cryptographic operations from it.

Best suited for: Controlled manual signing and some smaller release workflows.

Interactive token use can be difficult to scale across unattended build pipelines. Protect the token, PIN and signing workstation. Physical possession should not be the only security control.

Protect signing keys from export

For automated releases, compare managed signing options that keep private keys inside protected infrastructure.

DigiCert KeyLocker Code Signing

How Do the Key Protection Methods Compare?

Use this comparison as a starting point. Actual security depends on product configuration, key protection guarantees, access controls and release processes.

MethodKey exposure riskAutomation suitabilityTypical use
Hardware security moduleLow when correctly configuredHighEnterprise and high assurance signing
Managed cloud signingLow when the key is non exportableHighCI/CD and distributed teams
Dedicated signing serverDepends on key storage and access controlsHighCentralized internal release systems
Hardware tokenLow when correctly configuredLimited to moderateManual or controlled signing
Exportable key fileHigherHigh, but riskyAvoid for production signing where possible

What Does a Secure Code Signing Workflow Require?

Generate and protect the key

Generate the key inside an approved HSM or supported signing service whenever possible. Verify that the private key cannot be exported and that its protection meets the certificate's requirements.

Restrict signing permissions

Give signing access only to approved people, service identities and release pipelines. Separate permission to build software from permission to sign production releases.

Sign only approved artifacts

Require successful builds, tests and release checks before signing. Where practical, bind the signing request to a specific artifact digest, release identity and approved workflow.

Timestamp and verify

Apply a trusted timestamp where appropriate, then verify the resulting signature, certificate chain and artifact integrity before publishing the release. For timestamp details, review code signing and timestamping.

Record signing activity

Log who or what initiated the request, which artifact was signed, when it occurred and whether verification succeeded. Alert on unusual or unauthorized requests.

Review access regularly

Remove access when people change roles, review pipeline identities and permissions, and document the process for key rotation and suspected compromise.

For implementation details, read How to Sign Software in a CI/CD Pipeline and How to Automate Code Signing in CI/CD.

How Can You Protect Signing Keys in CI/CD Pipelines?

CI/CD automation makes signing repeatable, but a compromised build agent or pipeline account may still try to use signing credentials. Apply controls to both key storage and signing permissions.

  • Keep private key material out of pipelines. Do not commit keys or certificate bundles containing private keys to Git. Avoid exportable keys in environment variables, build configuration files, container images or workflow artifacts.
  • Authenticate securely. Use short lived credentials, workload identity or another supported authentication method where available. Avoid long lived shared credentials when a safer supported option exists.
  • Separate build and signing permissions. Restrict production signing to approved branches, protected release tags, trusted workflows or authorized release approvals.
  • Limit what can be signed. Where supported, restrict permitted identities, projects, artifacts or signing operations. Validate artifacts before they reach the signing service.
  • Protect logs and temporary files. Never log private key material, PINs, access tokens or sensitive signing credentials. Clean up temporary files and prevent secrets from entering build artifacts.
  • Verify after signing. A successful signing command does not establish that the correct file was signed or that its signature will validate on the target platform.

For platform specific implementation, see How to Sign Software in a CI/CD Pipeline.

Choose a certificate for your release workflow

Match the certificate to your operating system, signing format and distribution requirements before integrating it into the pipeline.

Explore code signing certificates

Can Secret Managers Protect Code Signing Private Keys?

A secret manager can protect passwords, API tokens and other credentials, but it is not automatically equivalent to non exportable private key storage. For example, storing a password that unlocks an exportable PFX file in a secret manager may reduce accidental exposure of the password. It does not prevent a pipeline from retrieving and copying the private key after decryption.

ApproachWhat it protectsImportant limitation
Secret managerCredentials and secrets at restRetrieved secrets may still be exposed to the workload.
Encrypted PFX fileKey material while encryptedThe key may be exported after decryption.
HSM backed signingKey operations within protected hardwareAccess to signing operations must still be restricted.
Managed cloud signingSigning access through a serviceSecurity depends on key custody, authentication and service controls.
If stronger key storage is not available yet: Apply strict access restrictions, use short lived credentials where possible, isolate the signing environment and establish a plan to move production keys into stronger protection.

What Should You Do If a Private Key Is Exposed?

Treat suspected private key exposure as a security incident, even if there is no evidence that the key has been misused.

Restrict access

Disable affected credentials and prevent further signing operations where appropriate.

Investigate the exposure

Review repository history, build logs, access records and signing activity to determine the possible scope.

Replace the key

Generate a new protected key and obtain a replacement certificate through the relevant certificate authority's process.

Rebuild and resign

Create clean release artifacts and sign them using the replacement key when required.

Notify affected parties

Follow applicable incident response, customer notification and regulatory requirements.

Removing a private key from the latest commit is not sufficient if it remains in repository history, backups, logs or cached artifacts. Follow a full incident response process.

Related guide: what happens if a code signing private key is compromised.

How Can You Verify Software Signed With a Protected Key?

Verify the actual release artifact rather than relying only on the signing service's success response. On Windows, Microsoft's SignTool can verify a signed executable using the Authenticode verification policy.

Windows SignToolsigntool verify /pa /v "MyApplication.exe"

This command checks the signature under the specified policy and displays verbose verification information. It does not verify that the private key was stored securely or that the release process was authorized.

Also confirm that:

  • The expected publisher is shown.
  • The signature is valid and the signed file has not changed.
  • The certificate chain and timestamp meet release requirements.
  • The verified artifact is the exact file being published.
  • The release process records the artifact hash and verification result.

For more detailed checks, see How to Verify Code Signed Software on Windows.

What Should You Check Before Releasing Signed Software?

Use this checklist when reviewing key protection and release access. Mark each item as your team confirms it.

Private key generated and stored in an approved protected environment
Private key is non exportable where supported and required
Production signing access restricted to approved identities
Build and signing permissions separated
Release approval and artifact validation enforced
No private keys or sensitive credentials committed to source control
Signing requests and outcomes recorded in audit logs
Timestamping configured where appropriate
Signed artifact verified before publication
Key rotation and compromise response documented

Prepare Windows releases for signing

Select a Windows code signing certificate and pair it with restricted signing access and mandatory artifact verification.

Windows code signing certificates

Frequently Asked Questions

Can I sign software without downloading the private key?

Yes. An HSM or a suitable managed cloud signing service can perform signing operations without exporting the private key. Your signing tool still needs authorized access to the cryptographic service.

Is storing a private key in a CI/CD secret variable safe?

It is generally riskier than using a non exportable key. A secret variable may protect the value at rest, but a pipeline that can retrieve and use an exportable key may expose it through a compromised job, process or log.

Does an HSM guarantee that my code signing key cannot be compromised?

No security control offers an absolute guarantee. An appropriately configured HSM can prevent private key extraction, but unauthorized users or compromised workloads may still misuse permitted signing operations. Authentication, access restrictions, monitoring and release controls remain essential.

Can cloud code signing work with automated software releases?

Yes. Many managed signing solutions support command line clients, APIs or CI/CD integrations. Confirm compatibility with your operating system, certificate, build platform and required signing format before adopting a service.

Is a hardware token better than cloud signing?

Neither is universally better. A hardware token can suit controlled manual signing, while cloud signing may be more convenient for automated and distributed release workflows. Compare key protection, access controls, automation support, auditability and operational requirements.

Should the certificate file and private key be stored together?

A public certificate may be distributed as needed, but the private key should remain protected. Avoid packaging exportable private keys with source code, build artifacts or application installers. Follow the certificate authority's storage requirements and your organization's key management policy.

What should I do if my code signing private key is leaked?

Restrict its use, investigate possible misuse, contact the certificate authority, evaluate revocation and replacement, and issue new releases using a replacement key when required. Remove exposed copies from repositories and storage, but do not assume deletion alone resolves the incident.