How to Create a Self-Signed Certificate With PowerShell [Snippet]

DZone 's Guide to

How to Create a Self-Signed Certificate With PowerShell [Snippet]

The development process often requires the use of a certificate, so let's learn how to make one using PowerShell.

· Security Zone ·
Free Resource

When we develop web-application or experiment with some technologies, it's quite common to need a certificate. A certificate for real world scenarios can be expensive, and it's over-engineering for testing purposes. So with this simple PowerShell script (on Windows), we can create a self-signed certificate for development enviroments.

$cert = New-SelfSignedCertificate -DnsName mydemowebapp.net -CertStoreLocation cert:\LocalMachine\My

$pwd = ConvertTo-SecureString -String "MyPassword" -Force -AsPlainText

Export-PfxCertificate -Cert $cert -FilePath C:\temp\cert.pfx -Password $pwd

With these few line of codes, we create and store a self-signed certificate in the Windows Certificate Store. With the last line (Export-PfxCertificate), we export the certificate for furher use for example to do some experiments with cloud providers.


GitHub Gist
certificate, code snippet, powershell, security, self signed certificate, ssl, web dev

Published at DZone with permission of Michele Ferracin , DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}