Programming

How do I create a self-signed certificate for code signing on Windows

25 September 2026 · 8 min read

How do I create a self-signed certificate for code signing on Windows

Creating a self-signed certificate for code signing on Windows is a crucial process for developers who want to ensure the integrity and authenticity of their software. It allows users to trust that the software they’re downloading hasn’t been tampered with and originates from a verified source. While commercial code signing certificates offer broader trust, self-signed certificates are a cost-effective solution, especially for internal testing, distribution, or open-source projects. This guide provides a comprehensive walkthrough on how to generate and utilize a self-signed code signing certificate on Windows, empowering you to take control of your software’s security.

Generating Your Self-Signed Certificate

The process begins with leveraging the power of the Certificate Manager, a built-in Windows utility. This tool provides a straightforward interface for generating and managing certificates.

Open the Certificate Manager by running certmgr.msc. Navigate to the Personal store and then to Certificates. Right-click in the main pane and select All Tasks > Request New Certificate…. This initiates the Certificate Enrollment wizard.

Proceed through the wizard, ensuring you select the Active Directory Enrollment Policy (if available) or the equivalent template that allows for code signing. If you don’t see an appropriate policy, you might need to configure your Active Directory or use the command-line tool certreq.exe for more advanced options.

Specifying Certificate Properties

During the enrollment process, you’ll be prompted to define specific properties for your certificate. This includes choosing a strong cryptographic algorithm, like SHA256 or higher, and specifying the intended purpose as Code Signing. It is imperative to correctly identify the intended use to ensure the certificate is recognized and trusted for its purpose.

It’s vital to specify a descriptive “Friendly name” for your certificate. This name will help you identify it later within the Certificate Manager. For example, “My Code Signing Certificate” or something similarly clear is a good practice.

Finally, ensure you specify a secure location to store the private key associated with your certificate. This key is crucial for signing code and should be protected accordingly. Consider using a hardware security module (HSM) for enhanced security.

Signing Your Code with the Certificate

Once your certificate is generated, you can utilize the command-line tool signtool.exe, which is part of the Windows SDK, to sign your code. The basic syntax is as follows: signtool sign /f "path/to/your/certificate.pfx" /p "your_certificate_password" /tr "http://timestamp.digicert.com" "path/to/your/executable.exe".

The /tr switch adds a timestamp to your signature, ensuring its validity even after the certificate expires. This allows users to continue running your signed software without security warnings. The timestamp server URL in the example is Digicert’s, but other reputable timestamping authorities exist.

For a smoother workflow, integrate code signing directly into your build process. Most Integrated Development Environments (IDEs) offer extensions or plugins to facilitate this integration, streamlining your development cycle.

Troubleshooting Common Issues

Occasionally, you might encounter issues during the code signing process. One common problem is an invalid certificate store. Double-check that your certificate is correctly installed in the Personal certificate store. Using the wrong certificate type can also lead to errors. Ensure your certificate is explicitly intended for Code Signing.

Incorrect password entry for the certificate’s private key is another frequent problem. Verify that you’re using the correct password. If you have forgotten the password, you’ll need to generate a new certificate.

  • Always double-check the certificate installation location.
  • Ensure your chosen certificate is specifically for code signing.

For more complex troubleshooting, consult the official Microsoft documentation or community forums dedicated to code signing. Leveraging these resources provides in-depth knowledge and community support for resolving complex issues.

Best Practices for Self-Signed Certificates

While self-signed certificates are beneficial, remember they don’t carry the same weight as those issued by trusted Certificate Authorities (CAs). Users will initially encounter warnings about the software’s publisher being unknown. To mitigate this, clearly communicate the nature of the self-signed certificate to your users and explain how to install it as a trusted publisher on their systems.

Regularly update your self-signed certificates. Unlike CA-issued certificates with longer validity periods, you should renew self-signed certificates more frequently, ideally annually. This practice ensures your software remains trusted and minimizes potential security risks associated with outdated certificates.

  1. Communicate clearly with your users about the self-signed certificate.
  2. Establish a regular renewal schedule for your self-signed certificates.

Remember, carefully manage your private keys. Securely store them and follow the principle of least privilege, granting access only to authorized personnel. This practice significantly reduces the risk of unauthorized code signing.

Infographic Placeholder: Visual guide on the code signing process.

Consider using a dedicated code signing certificate from a reputable Certificate Authority (CA) for wider trust and a more seamless user experience, particularly for publicly distributed software. Tools like OpenSSL offer alternative methods for certificate generation. Explore various tools and choose one that aligns with your specific needs and technical expertise. Check out this helpful resource: Learn more about code signing best practices.

See also information about digital signatures and the use of OpenSSL. For more in-depth technical guidance on using signtool.exe, refer to Microsoft’s official documentation. Internal link anchor text example. By following these best practices, you can leverage the advantages of self-signed certificates while maintaining a high level of security and user trust.

  • Benefit: Cost-effective solution for testing and internal distribution.
  • Drawback: Requires users to manually establish trust.

FAQ

Q: Why is my code signing certificate not trusted?

A: This is likely because the certificate is self-signed and not recognized by the user’s system. You’ll need to add the certificate as a trusted publisher on each user’s machine.

Implementing robust code signing practices is essential for safeguarding your software’s integrity and fostering user trust. By understanding the nuances of self-signed certificates and adhering to best practices, you can effectively secure your code while navigating the complexities of software distribution. Begin securing your code today and instill confidence in your users. Explore further topics like timestamping authorities and different types of code signing certificates to deepen your understanding.

Question & Answer :
How do I create a self-signed certificate for code signing using the Windows SDK?

Updated Answer

If you are using the following Windows versions or later: Windows Server 2012, Windows Server 2012 R2, or Windows 8.1 then MakeCert is now deprecated, and Microsoft recommends using the PowerShell Cmdlet New-SelfSignedCertificate.

If you’re using an older version such as Windows 7, you’ll need to stick with MakeCert or another solution. Some people suggest the Public Key Infrastructure Powershell (PSPKI) Module.

Original Answer

While you can create a self-signed code-signing certificate (SPC - Software Publisher Certificate) in one go, I prefer to do the following:

Creating a self-signed certificate authority (CA)

makecert -r -pe -n "CN=My CA" -ss CA -sr CurrentUser ^ -a sha256 -cy authority -sky signature -sv MyCA.pvk MyCA.cer 

(^ = allow batch command-line to wrap line)

This creates a self-signed (-r) certificate, with an exportable private key (-pe). It’s named “My CA”, and should be put in the CA store for the current user. We’re using the SHA-256 algorithm. The key is meant for signing (-sky).

The private key should be stored in the MyCA.pvk file, and the certificate in the MyCA.cer file.

Importing the CA certificate

Because there’s no point in having a CA certificate if you don’t trust it, you’ll need to import it into the Windows certificate store. You can use the Certificates MMC snapin, but from the command line:

certutil -user -addstore Root MyCA.cer 

Creating a code-signing certificate (SPC)

makecert -pe -n "CN=My SPC" -a sha256 -cy end ^ -sky signature ^ -ic MyCA.cer -iv MyCA.pvk ^ -sv MySPC.pvk MySPC.cer 

It is pretty much the same as above, but we’re providing an issuer key and certificate (the -ic and -iv switches).

We’ll also want to convert the certificate and key into a PFX file:

pvk2pfx -pvk MySPC.pvk -spc MySPC.cer -pfx MySPC.pfx 

If you are using a password please use the below

pvk2pfx -pvk MySPC.pvk -spc MySPC.cer -pfx MySPC.pfx -po fess 

If you want to protect the PFX file, add the -po switch, otherwise PVK2PFX creates a PFX file with no passphrase.

Using the certificate for signing code

signtool sign /v /f MySPC.pfx ^ /t http://timestamp.url MyExecutable.exe 

(See why timestamps may matter)

If you import the PFX file into the certificate store (you can use PVKIMPRT or the MMC snapin), you can sign code as follows:

signtool sign /v /n "Me" /s SPC ^ /t http://timestamp.url MyExecutable.exe 

Some possible timestamp URLs for signtool /t are:

  • http://timestamp.verisign.com/scripts/timstamp.dll
  • http://timestamp.globalsign.com/scripts/timstamp.dll
  • http://timestamp.comodoca.com/authenticode
  • http://timestamp.digicert.com

Full Microsoft documentation

Downloads

For those who are not .NET developers, you will need a copy of the Windows SDK and .NET framework. A current link is available here: [SDK & .NET][5] (which installs makecert in C:\\Program Files\\Microsoft SDKs\\Windows\\v7.1). Your mileage may vary. MakeCert is available from the Visual Studio Command Prompt. Visual Studio 2015 does have it, and it can be launched from the Start Menu in Windows 7 under “Developer Command Prompt for VS 2015” or “VS2015 x64 Native Tools Command Prompt” (probably all of them in the same folder).