Use the New-SelfSignedCertificate cmdlet in PowerShell or the OpenSSL tool to create a self-signed certificate on Windows. This generates a digital certificate valid for testing, internal services, or local development without requiring a public certificate authority.
Self-signed certificates are cryptographic files that bind a public key to an identity. They're signed by the same entity that created them, not a trusted third party. On Windows, you can generate them via PowerShell's native New-SelfSignedCertificate cmdlet or through OpenSSL installed via Windows Subsystem for Linux (WSL) or Windows Installer.
These certificates are not trusted by default in web browsers or operating systems. They're intended for internal use, such as securing local APIs, testing HTTPS endpoints, or configuring secure communication between services on a private network.
The process begins with generating a public-private key pair. The private key stays on your machine. The public key is embedded in the certificate, which includes metadata like the subject name, validity period, and signature algorithm.
When you run New-SelfSignedCertificate in PowerShell, Windows uses the CNG (Cryptography Next Generation) API to create the key pair and sign the certificate with the private key. The resulting .cer or .pfx file contains the public key and associated information.
For example, a command like:
New-SelfSignedCertificate -DnsName "localhost" -CertStoreLocation "cert:\LocalMachine\My" -NotAfter (Get-Date).AddYears(1)
creates a certificate valid for one year, bound to the DNS name localhost, and stores it in the Local Machine's personal certificate store.
Two primary output formats exist: .cer and .pfx.
| Format | Contains | Use Case | Command Example |
|---|---|---|---|
| .cer | Public key only | Client trust, server configuration | Export-Certificate -Cert Cert:\LocalMachine\My\{thumbprint} -FilePath C:\certs\server.cer |
| .pfx | Private key + public key + chain | Application deployment, secure storage | Export-PfxCertificate -Cert Cert:\LocalMachine\My\{thumbprint} -FilePath C:\certs\server.pfx -Password (ConvertTo-SecureString -String "P@ssw0rd!" -Force) |
Use .cer files when distributing to clients who only need to verify authenticity. Use .pfx when deploying to applications that require both public and private keys, such as ASP.NET Core apps or IIS sites.
Developers use self-signed certificates to test HTTPS locally. For example, when building a web API with dotnet run and enabling HTTPS via launchSettings.json, the app defaults to a self-signed cert if none is provided.
System administrators deploy them to secure internal services like LDAP, SSO portals, or internal websites. A company might host an intranet site at https://hr.internal and use a self-signed certificate to avoid relying on external CA costs.
Security teams use them during penetration testing to simulate encrypted traffic without exposing production systems.
Many assume self-signed certificates are inherently insecure. That's incorrect. They're cryptographically sound. The issue lies in trust-not encryption strength. Browsers block access to sites using self-signed certs because they can't verify the identity of the server.
A common mistake is assuming the certificate will work across devices. It won't unless the certificate is manually imported into the Trusted Root Certification Authorities store on each client machine.
Another error: using the same certificate across multiple environments. This creates a single point of failure. Always generate unique certificates per environment (dev, staging, prod).
Suppose you're building a Node.js API with Express and want to enable HTTPS for local testing.
New-SelfSignedCertificate -DnsName "api.local" -CertStoreLocation "cert:\LocalMachine\My" -NotAfter (Get-Date).AddYears(1) -KeyExportPolicy Exportable -KeySpec Signature -HashAlgorithm SHA256
This creates a certificate valid for api.local, exports the private key, and uses SHA-256 hashing.
Next, export the PFX file:
Export-PfxCertificate -Cert Cert:\LocalMachine\My\{thumbprint} -FilePath C:\certs\api.pfx -Password (ConvertTo-SecureString -String "SecurePass123!" -Force)
Then configure your Node.js app to use the PFX file:
const https = require('https');
const fs = require('fs');
const options = {
keyFile: 'C:\\certs\\api.pfx',
passphrase: 'SecurePass123!',
requestCert: false,
rejectUnauthorized: false
};
https.createServer(options, (req, res) => {
res.writeHead(200);
res.end('Hello from HTTPS!');
}).listen(3000);
Now visiting https://localhost:3000 shows a warning in the browser-but the connection works. You can bypass the warning to test functionality.
I once set up a local Kubernetes cluster using Minikube on Windows. The dashboard required HTTPS. I generated a self-signed certificate using PowerShell, exported it as a .pfx, and imported it into the Windows certificate store. After adding the root certificate to the trusted list, the dashboard loaded without errors. This was faster than setting up a Let's Encrypt domain for local testing.
Generating a self-signed certificate is not the same as obtaining a trusted SSL/TLS certificate from a CA like DigiCert or Let's Encrypt. Those are validated, publicly trusted, and suitable for public websites.
It's also not a substitute for proper PKI (Public Key Infrastructure) in enterprise environments. Large organizations use internal CAs to issue certificates with hierarchical trust chains. Self-signed certs are too blunt for centralized management.
Finally, it's not a security fix. A self-signed certificate doesn't protect against man-in-the-middle attacks unless paired with proper trust verification. It only ensures encryption.
PowerShell's New-SelfSignedCertificate is the standard method on Windows. It's built into Windows 8.1 and later, including Windows 10 and 11.
Alternatively, use OpenSSL. Install it via WSL or the standalone installer from https://slproweb.com/products/Win32OpenSSL.html. Run:
openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 365 -nodes -subj "/CN=localhost"
This produces a PEM-encoded certificate and private key. Convert to PFX using:
openssl pkcs12 -export -out cert.pfx -inkey key.pem -in cert.pem -passout pass:P@ssw0rd!
For automation, scripts can generate certificates in bulk. One team I worked with wrote a PowerShell script that generated 50 unique self-signed certs for testing microservices. Each had a different Common Name and expiry date.
Understanding how to generate self signed certificate Windows is essential for developers, testers, and system admins working in isolated or controlled environments. It enables secure communication without external dependencies.
Use this method when you need a quick, temporary certificate for testing, internal tools, or development. Avoid it for public-facing services. Always validate the certificate's purpose and trust model before deployment.