Generate self-signed certificates

Generate self-signed certificates

You can use PowerShell to generate self-signed certificates. The PKI Client can be used to generate a self-signed certificate.

PowerShell
$cert = New-SelfSignedCertificate -DnsName @("contoso.com", "www.contoso.com") -CertStoreLocation "cert:\LocalMachine\My"

The certificate will be generated, but for the purposes of testing, should be placed in a cert store for testing in a browser.

PowerShell
$certKeyPath = "c:\certs\contoso.com.pfx"
$password = ConvertTo-SecureString 'password' -AsPlainText -Force
$cert | Export-PfxCertificate -FilePath $certKeyPath -Password $password
$rootCert = $(Import-PfxCertificate -FilePath $certKeyPath -CertStoreLocation 'Cert:\LocalMachine\Root' -Password $password)

At this point, the certificates should be viewable from an MMC snap-in.

可以直接win+R,输入certmgr.msc

 

Clean up

PowerShell
$cert | Remove-Item
Get-ChildItem $certFilePath | Remove-Item
$rootCert | Remove-item


 

posted @ 2021-06-16 16:14  ChuckLu  阅读(128)  评论(0编辑  收藏  举报