Skip to content

Instantly share code, notes, and snippets.

@goyalmohit
Created September 23, 2018 09:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save goyalmohit/2ad70e2341121d000841766f0d4ecbbc to your computer and use it in GitHub Desktop.
Save goyalmohit/2ad70e2341121d000841766f0d4ecbbc to your computer and use it in GitHub Desktop.
Generates Self Signed SSL Certificate
# Generates Certificate and import it to Current user's certificate Store
$certificate = New-SelfSignedCertificate `
-Subject my_web_domain`
-DnsName my_web_domain `
-KeyAlgorithm RSA `
-KeyLength 2048 `
-NotBefore (Get-Date) `
-NotAfter (Get-Date).AddYears(1) `
-CertStoreLocation "cert:CurrentUser\My" `
-FriendlyName "Localhost Certificate for .NET Core" `
-HashAlgorithm SHA256 `
-KeyUsage DigitalSignature, KeyEncipherment, DataEncipherment `
-TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.1")
$certificatePath = 'Cert:\CurrentUser\My\' + ($certificate.ThumbPrint)
# Create temporary certificate path
$tmpPath = "C:\Certs"
If(!(test-path $tmpPath))
{
New-Item -ItemType Directory -Force -Path $tmpPath
}
# Set certificate password here
$pfxPassword = ConvertTo-SecureString -String "YourSecurePassword" -Force -AsPlainText
$pfxFilePath = "C:\Certs\my_web_domain.pfx"
$cerFilePath = "C:\Certs\my_web_domain.cer"
# Create pfx certificate
Export-PfxCertificate -Cert $certificatePath -FilePath $pfxFilePath -Password $pfxPassword
Export-Certificate -Cert $certificatePath -FilePath $cerFilePath
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment