Create a Self‑Signed Certificate for Code Signing on Windows
In this article
Yes, you can create a self‑signed certificate for code signing on Windows using built‑in tools such as PowerShell and the MakeCert utility. A self‑signed code‑signing certificate lets you digitally sign executables, PowerShell scripts, or MSI packages during development or internal distribution without purchasing a commercial certificate.
What You’ll Need
- Windows 10 or Windows 11 (any edition with administrative rights)
- PowerShell 5.1 or later – included with modern Windows installations
- Windows SDK (optional, provides
makecert.exeif you prefer the older tool) - Administrator privileges for creating and exporting the certificate
- A strong password to protect the exported private key (PFX file)
Step‑By‑Step
- Open PowerShell as Administrator. Right‑click the Start button, choose Windows PowerShell (Admin), and confirm the UAC prompt.
-
Generate the certificate. Run the following command, adjusting the subject name and validity period as needed:
This creates a certificate with the Code Signing OID (1.3.6.1.5.5.7.3.3) and stores it in the current user’sNew-SelfSignedCertificate -Type Custom \ -Subject "CN=MyCodeSigningCert" \ -KeySpec Signature \ -KeyExportPolicy Exportable \ -HashAlgorithm SHA256 \ -KeyLength 2048 \ -NotAfter (Get-Date).AddYears(2) \ -CertStoreLocation "Cert:\CurrentUser\My" \ -FriendlyName "My Code Signing Cert" \ -TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.3")Personalstore. -
Verify the certificate exists. Execute:
You should see the newly created entry with a thumbprint.Get-ChildItem Cert:\CurrentUser\My | Where-Object {$_.Subject -like "*MyCodeSigningCert*"} -
Export the certificate to a PFX file. Replace
<Thumbprint>with the value from the previous step and choose a secure file path:
The$pwd = ConvertTo-SecureString -String "YourStrongPassword!" -Force -AsPlainText Export-PfxCertificate -Cert "Cert:\CurrentUser\My\<Thumbprint>" \ -FilePath "C:\Temp\MyCodeSigningCert.pfx" \ -Password $pwd-Passwordargument protects the private key; keep the password safe. -
(Optional) Install the certificate in the Trusted Root store for testing. This step is only needed if you want Windows to trust the signature on the same machine:
Importing intoImport-PfxCertificate -FilePath "C:\Temp\MyCodeSigningCert.pfx" \ -CertStoreLocation "Cert:\CurrentUser\Root" -Password $pwdRoottells Windows to treat the certificate as a trusted authority. -
Sign a file with
signtool.exe.signtoolships with the Windows SDK. Assuming you have it installed, run:
Thesigntool sign /fd SHA256 /a /f "C:\Temp\MyCodeSigningCert.pfx" /p "YourStrongPassword!" "C:\Path\To\YourApp.exe"/aswitch selects the best certificate automatically; you can also specify/sha1 <Thumbprint>for certainty. -
Validate the signature. Use:
A successful verification confirms the certificate was applied correctly.signtool verify /pa "C:\Path\To\YourApp.exe"
Common Mistakes
- Omitting
-KeySpec Signatureresults in a certificate that cannot be used for code signing. - Not marking the key as
Exportableprevents you from exporting a PFX file later. - Using the default hash algorithm (SHA1) – many modern tools reject SHA1 signatures; always use SHA256 or stronger.
- Saving the PFX without a password or using a weak password exposes the private key.
- Importing the certificate only into the
Personalstore but not intoTrusted Rootwhen testing on the same machine, causing Windows to flag the signature as untrusted. - Attempting to sign with
signtoolfrom a non‑elevated command prompt; the tool needs access to the private key.
Tips
- Always choose a key length of at least 2048 bits; 4096 bits adds extra security at the cost of a slightly larger signature.
- Set the certificate’s validity period to the shortest practical length – two years is common for internal development.
- When distributing internally, consider publishing the certificate to the corporate Group Policy Trusted Root store so every workstation trusts the signatures automatically.
- If you prefer an open‑source tool,
opensslcan generate a PKCS#12 file thatsigntoolalso accepts. - Keep the PFX file in a secure location and restrict read permissions to only the accounts that need to sign code.
Troubleshooting
Signature is reported as invalid. Verify the Enhanced Key Usage (EKU) includes the Code Signing OID. Run:
Get-ChildItem Cert:\CurrentUser\My\<Thumbprint> | Select-Object -ExpandProperty EnhancedKeyUsageList
If the OID 1.3.6.1.5.5.7.3.3 is missing, recreate the certificate with the -TextExtension parameter shown above.
Signtool cannot find the certificate. Ensure you are running the command from an elevated prompt and that the -f path points to the correct PFX file. You can also specify the certificate directly with /sha1 <Thumbprint> to avoid ambiguity.
Makecert.exe is not recognized. Install the Windows 10 SDK (or the latest Windows SDK) and add its bin directory (e.g., C:\Program Files (x86)\Windows Kits\10\bin\x64) to your PATH environment variable.
Export‑PfxCertificate fails with “Access denied”. The private key may be marked as non‑exportable. Ensure you used -KeyExportPolicy Exportable when creating the certificate, and run the PowerShell session as Administrator.
After signing, Windows Defender SmartScreen still warns users. SmartScreen checks the reputation of the signing certificate’s publisher. A self‑signed certificate has no reputation, so the warning is expected for external distribution. Use a trusted CA for public releases.
Frequently Asked Questions
Can I use a self‑signed certificate to sign drivers?
No. Windows requires kernel‑mode drivers to be signed by a trusted Microsoft‑issued certificate. Self‑signed certificates are only suitable for user‑mode applications and internal testing.
Do I need to install the Windows SDK to use signtool?
Yes. signtool.exe is part of the Windows SDK. Installing the SDK also provides makecert.exe if you prefer that older utility.
What hash algorithm should I use?
SHA256 is the current industry standard and is accepted by all modern Windows versions. Avoid SHA1 because it is deprecated.
How can I share the certificate with teammates?
Export the PFX file with a strong password and store it in a secure internal repository (e.g., a protected network share). Team members can import it using Import-PfxCertificate on their own machines.
Will this certificate work on other platforms like macOS or Linux?
The certificate format (PFX) is cross‑platform, but code‑signing tools differ. macOS uses codesign with a different certificate type, and Linux typically uses GPG. You would need to generate a platform‑specific certificate for those environments.
Can I renew the certificate before it expires?
Yes. Create a new self‑signed certificate with the same subject name and replace the old one. Remember to update any scripts or build pipelines that reference the old thumbprint.