pexels-photo-59628

Making a Self-Signed Certificate

A lot of services on Azure and on-premis require us to create or buy certificates. Now there are a couple of ways to create certificates. I used to do it using makecert

makecert -sky exchange -r -n "CN=<Domain Name>" -pe -a sha1 -len 2048 -ss My -sv <Domain Name>.pvk <Domain Name>.cer 
 
pvk2pfx -pvk <Domain Name>.pvk -pi <Password> -spc <Domain Name>.cer -pfx <Domain Name>.pfx

Recently, I started making my certificates using PowerShell

$CertPassword = '<Password>'
$CertDNSName = '<Domain Name>'

$SecurePassword = ConvertTo-SecureString -String $CertPassword `
                                         -AsPlainText `
                                         -Force

$CertFileFullPath = $(Join-Path (Split-Path -Parent 'C:\Users\<User ID>\Desktop\') "$CertDNSName.pfx")

$NewCert = New-SelfSignedCertificate -CertStoreLocation Cert:\CurrentUser\My `
                                     -DnsName $CertDNSName

Export-PfxCertificate -FilePath $CertFileFullPath `
                      -Password $SecurePassword `
                      -Cert $NewCert

Why PowerShell? That’s a valid question right, I mean we’ve used makecert for ever right?

I use the PowerShell CMDLETs because it feels right. When I’m building PowerShell scripts I tend to limit the switched between scripting and programming languages. I find that sticking to one or few of these languages results in scripts that are easier to maintain.

3 responses to Using PowerShell to Make a Self-Signed Certificate

  1. 

    Any chance you could do a post on creating/using a LetsEncrypt SSL Certificate on Azure?

    Like

Trackbacks and Pingbacks:

  1. Dew Drop – March 21, 2016 (#2212) | Morning Dew - March 21, 2016

    […] Using PowerShell to Make a Self-Signed Certificate (Alexandre Brisebois) […]

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s