Created
September 23, 2018 09:25
-
-
Save goyalmohit/2ad70e2341121d000841766f0d4ecbbc to your computer and use it in GitHub Desktop.
Generates Self Signed SSL Certificate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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