[筆記]Windows自建SSL 憑證給開發測試的localhost使用

開發網站時,需要再本地端IIS架設網站測試,但沒有SSL憑證導致使用https協定瀏覽時會出現不安全網站提示

可以參考
https://docs.microsoft.com/zh-tw/windows/uwp/debug-test-perf/device-portal-ssl

產生安全性憑證檔(.cer)
$CN = "你自訂的名稱"
$OutputPath = "c:\temp\"

# Create root certificate authority
$FilePath = $OutputPath + "你自訂的名稱.cer"
$Subject =  "CN="+$CN
$rootCA = New-SelfSignedCertificate -certstorelocation cert:\currentuser\my -Subject $Subject -HashAlgorithm "SHA512" -KeyUsage CertSign,CRLSign
$rootCAFile = Export-Certificate -Cert $rootCA -FilePath $FilePath
建立 SSL 憑證(.pfx)
$IssuedTo = "你的Domin名稱"
$Password = "給憑證設定一組密碼"
$OutputPath = "c:\temp\"
$rootCA = Import-Certificate -FilePath C:\temp\你自訂的名稱(安全憑證檔名).cer -CertStoreLocation Cert:\CurrentUser\My\

# Create SSL cert signed by certificate authority
$IssuedToClean = $IssuedTo.Replace(":", "-").Replace(" ", "_")
$FilePath = $OutputPath + $IssuedToClean + ".pfx"
$Subject = "CN="+$IssuedTo
$cert = New-SelfSignedCertificate -certstorelocation cert:\localmachine\my -Subject $Subject -DnsName $IssuedTo -Signer $rootCA -HashAlgorithm "SHA512"
$certFile = Export-PfxCertificate -cert $cert -FilePath $FilePath -Password (ConvertTo-SecureString -String $Password -Force -AsPlainText)

到C:\temp 找到剛剛產出的兩個檔案