it:ad:powershell:howto:create_a_self-signed_certificate:home

IT:AD:PowerShell:HowTo:Create A Self-Signed Certificate

Get-Command -Module PKI

Will show you several commands:

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Cmdlet          Add-CertificateEnrollmentPolicyServer              1.0.0.0    PKI
Cmdlet          Export-Certificate                                 1.0.0.0    PKI
Cmdlet          Export-PfxCertificate                              1.0.0.0    PKI
Cmdlet          Get-Certificate                                    1.0.0.0    PKI
Cmdlet          Get-CertificateAutoEnrollmentPolicy                1.0.0.0    PKI
Cmdlet          Get-CertificateEnrollmentPolicyServer              1.0.0.0    PKI
Cmdlet          Get-CertificateNotificationTask                    1.0.0.0    PKI
Cmdlet          Get-PfxData                                        1.0.0.0    PKI
Cmdlet          Import-Certificate                                 1.0.0.0    PKI
Cmdlet          Import-PfxCertificate                              1.0.0.0    PKI
Cmdlet          New-CertificateNotificationTask                    1.0.0.0    PKI
Cmdlet          New-SelfSignedCertificate                          1.0.0.0    PKI
Cmdlet          Remove-CertificateEnrollmentPolicyServer           1.0.0.0    PKI
Cmdlet          Remove-CertificateNotificationTask                 1.0.0.0    PKI
Cmdlet          Set-CertificateAutoEnrollmentPolicy                1.0.0.0    PKI
Cmdlet          Switch-Certificate                                 1.0.0.0    PKI
Cmdlet          Test-Certificate                                   1.0.0.0    PKI

We can use

New-SelfSignedCertificate [-SecurityDescriptor <FileSecurity>] [-TextExtension <String[]>]
 [-Extension <X509Extension[]>] [-HardwareKeyUsage <HardwareKeyUsage[]>]
 [-KeyUsageProperty <KeyUsageProperty[]>] [-KeyUsage <KeyUsage[]>] [-KeyProtection <KeyProtection[]>]
 [-KeyExportPolicy <KeyExportPolicy[]>] [-KeyLength <Int32>] [-KeyAlgorithm <String>] [-SmimeCapabilities]
 [-ExistingKey] [-KeyLocation <String>] [-SignerReader <String>] [-Reader <String>] [-SignerPin <SecureString>]
 [-Pin <SecureString>] [-KeyDescription <String>] [-KeyFriendlyName <String>] [-Container <String>]
 [-Provider <String>] [-CurveExport <CurveParametersExportType>] [-KeySpec <KeySpec>] [-Type <CertificateType>]
 [-FriendlyName <String>] [-NotAfter <DateTime>] [-NotBefore <DateTime>] [-SerialNumber <String>]
 [-Subject <String>] [-DnsName <String[]>] [-SuppressOid <String[]>] [-HashAlgorithm <String>]
 [-AlternateSignatureAlgorithm] [-TestRoot] [-Signer <Certificate>] [-CloneCert <Certificate>]
 [-CertStoreLocation <String>] [-WhatIf] [-Confirm] [<CommonParameters>]

To make a new cert:

<xxh powershell> New-SelfSignedCertificate -DnsName “localhost”, “localhost” -CertStoreLocation “cert:\LocalMachine\My”

-DnsName “www.fabrikam.com”, “www.contoso.com” -FriendlyName “Shared Dev localhost” -KeyUsageProperty All -NotAfter (Get-Date).AddMonths(84) -KeyExportPolicy Exportable -KeyFriendlyName “Localhost Key” -SignatureAlgorithm SHA512 - StoreLocation Machine (rather than CurrentUser) </sxh>

$pwd = ConvertTo-SecureString -String ‘passw0rd!’ -Force -AsPlainText


$cert = New-SelfSignedCertificate -DnsName "localhost" -FriendlyName "DEV Shared Localhost" -HashAlgorithm SHA512 -NotAfter (Get-Date).AddMonths(120)

The above command installs the cert where located.

To export it to the rest of the team:

$path = 'cert:\LocalMachine\my\' + $cert.thumbprint 
$pwd = ConvertTo-SecureString -String ‘passw0rd!’ -Force -AsPlainText
Export-PfxCertificate -cert $path -FilePath '.\dev-localhost.pfx' -Password $pwd

Chrome can be a real cow.

  • If it is returning NET::ERR_CERT_AUTHORITY_INVALID

One option is to type the type the following into a new tab:

chrome://flags/#allow-insecure-localhost

  • /home/skysigal/public_html/data/pages/it/ad/powershell/howto/create_a_self-signed_certificate/home.txt
  • Last modified: 2023/11/04 02:26
  • by 127.0.0.1