{"id":3126,"date":"2026-03-08T12:27:51","date_gmt":"2026-03-08T10:27:51","guid":{"rendered":"https:\/\/itsimple.info\/?p=3126"},"modified":"2026-03-08T12:27:51","modified_gmt":"2026-03-08T10:27:51","slug":"how-to-create-local-certificate-for-testing-purpose","status":"publish","type":"post","link":"https:\/\/itsimple.info\/?p=3126","title":{"rendered":"How to create Local Certificate for testing Purpose"},"content":{"rendered":"\n<p>Sometimes for developer needs. You want to create a Certificates which will implement HTTPS or code sighing, I have created a Powershell Script that have a simple GUI and create Certificates for all kind of needs, this is the script :<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Add-Type -AssemblyName System.Windows.Forms<br>Add-Type -AssemblyName System.Drawing<br><br># --- Core Function ---<br><br># Get CA cert from local computer (Local Machine -&gt; My)<br>function Get-LocalCAs {<br>    Get-ChildItem -Path Cert:\\LocalMachine\\My | Where-Object { <br>        $_.Extensions | Where-Object { $_.Oid.FriendlyName -eq \"Key Usage\" -and $_.Format(0) -like \"*Certificate Signing*\" }<br>    }<br>}<br><br># Export PFX (include private key)<br>function Export-AsPfx {<br>    param ($Cert, $FilePath, $Password)<br>    $SecurePassword = ConvertTo-SecureString -String $Password -Force -AsPlainText<br>    Export-PfxCertificate -Cert $Cert -FilePath \"$FilePath.pfx\" -Password $SecurePassword<br>}<br><br># Log in RichTextBox<br>function Write-Log {<br>    param([string]$Message, $Color = [System.Drawing.Color]::SpringGreen)<br>    if ($Color -is [string]) { $Color = [System.Drawing.Color]::FromName($Color) }<br>    $TxtLog.SelectionStart = $TxtLog.TextLength<br>    $TxtLog.SelectionLength = 0<br>    $TxtLog.SelectionColor = $Color<br>    $TxtLog.AppendText(\"$Message`r`n\")<br>    $TxtLog.SelectionColor = $TxtLog.ForeColor <br>    $TxtLog.ScrollToCaret()<br>}<br><br># --- GUI ---<br>$Form = New-Object System.Windows.Forms.Form<br>$Form.Text = \"CertCreator Pro - SAN &amp; CA Manager\"<br>$Form.Size = \"750,950\"<br>$Form.StartPosition = \"CenterScreen\"<br>$Form.BackColor = \"WhiteSmoke\"<br><br>$FontLabel = New-Object System.Drawing.Font(\"Segoe UI\", 10, [System.Drawing.FontStyle]::Bold)<br>$FontInput = New-Object System.Drawing.Font(\"Segoe UI\", 11)<br>$FontLog = New-Object System.Drawing.Font(\"Consolas\", 11)<br><br>$CurrentY = 30<br>$LabelX = 40<br>$InputX = 320<br>$InputWidth = 360<br><br># 1. Common Name (CN)<br>$L1 = New-Object System.Windows.Forms.Label; $L1.Text = \"Common Name (CN):\"; $L1.Location = \"$LabelX,$CurrentY\"; $L1.Size = \"260,30\"; $L1.Font = $FontLabel; $Form.Controls.Add($L1)<br>$TxtCN = New-Object System.Windows.Forms.TextBox; $TxtCN.Location = \"$InputX,$CurrentY\"; $TxtCN.Width = $InputWidth; $TxtCN.Font = $FontInput; $Form.Controls.Add($TxtCN)<br><br>$CurrentY += 50<br># 2. SAN (Multi-Domain) <br>$L_SAN = New-Object System.Windows.Forms.Label; $L_SAN.Text = \"Multi-Domain (SAN):`n(mail.com, *.web.com)\"; $L_SAN.Location = \"$LabelX,$CurrentY\"; $L_SAN.Size = \"260,50\"; $L_SAN.Font = $FontLabel; $Form.Controls.Add($L_SAN)<br>$TxtSAN = New-Object System.Windows.Forms.TextBox; $TxtSAN.Location = \"$InputX,$CurrentY\"; $TxtSAN.Width = $InputWidth; $TxtSAN.Font = $FontInput; $Form.Controls.Add($TxtSAN)<br><br>$CurrentY += 60<br># 3. Certs option<br>$L2 = New-Object System.Windows.Forms.Label; $L2.Text = \"Certificate Type:\"; $L2.Location = \"$LabelX,$CurrentY\"; $L2.Size = \"260,30\"; $L2.Font = $FontLabel; $Form.Controls.Add($L2)<br>$ComboType = New-Object System.Windows.Forms.ComboBox; $ComboType.Location = \"$InputX,$CurrentY\"; $ComboType.Width = $InputWidth; $ComboType.Font = $FontInput; $ComboType.DropDownStyle = \"DropDownList\"<br>$ComboType.Items.AddRange(@(\"IIS Web Server\", \"Root CA\", \"Code Signing\", \"Hyper-V Replication\"))<br>$Form.Controls.Add($ComboType)<br><br>$CurrentY += 50<br># 4. CA to sign the certificate<br>$L_Sign = New-Object System.Windows.Forms.Label; $L_Sign.Text = \"Sign with existing CA?\"; $L_Sign.Location = \"$LabelX,$CurrentY\"; $L_Sign.Size = \"260,30\"; $L_Sign.Font = $FontLabel; $Form.Controls.Add($L_Sign)<br>$ComboCAs = New-Object System.Windows.Forms.ComboBox; $ComboCAs.Location = \"$InputX,$CurrentY\"; $ComboCAs.Width = $InputWidth; $ComboCAs.Font = $FontInput; $ComboCAs.DropDownStyle = \"DropDownList\"<br>$Form.Controls.Add($ComboCAs)<br><br># reload CA cert<br>$ComboCAs.Items.Add(\"-- Self-Signed (No CA) --\")<br>$ComboCAs.SelectedIndex = 0<br>foreach ($ca in (Get-LocalCAs)) { [void]$ComboCAs.Items.Add(\"$($ca.Subject) [$($ca.Thumbprint)]\") }<br><br>$CurrentY += 50<br># 5. Password for PFX<br>$L4 = New-Object System.Windows.Forms.Label; $L4.Text = \"PFX Export Password:\"; $L4.Location = \"$LabelX,$CurrentY\"; $L4.Size = \"260,30\"; $L4.Font = $FontLabel; $Form.Controls.Add($L4)<br>$TxtPass = New-Object System.Windows.Forms.TextBox; $TxtPass.Location = \"$InputX,$CurrentY\"; $TxtPass.Width = $InputWidth; $TxtPass.Font = $FontInput; $TxtPass.PasswordChar = '*'; $Form.Controls.Add($TxtPass)<br><br>$CurrentY += 50<br># 6. Expiration Date<br>$L5 = New-Object System.Windows.Forms.Label; $L5.Text = \"Expiration Date:\"; $L5.Location = \"$LabelX,$CurrentY\"; $L5.Size = \"260,30\"; $L5.Font = $FontLabel; $Form.Controls.Add($L5)<br>$DateExp = New-Object System.Windows.Forms.DateTimePicker; $DateExp.Location = \"$InputX,$CurrentY\"; $DateExp.Width = $InputWidth; $DateExp.Font = $FontInput; $Form.Controls.Add($DateExp)<br><br>$CurrentY += 80<br># Generate Button<br>$BtnCreate = New-Object System.Windows.Forms.Button<br>$BtnCreate.Text = \"GENERATE CERTIFICATE\"; $BtnCreate.Location = \"40,$CurrentY\"; $BtnCreate.Width = 640; $BtnCreate.Height = 60<br>$BtnCreate.BackColor = \"SteelBlue\"; $BtnCreate.ForeColor = \"White\"; $BtnCreate.Font = New-Object System.Drawing.Font(\"Segoe UI\", 12, [System.Drawing.FontStyle]::Bold)<br>$Form.Controls.Add($BtnCreate)<br><br>$CurrentY += 80<br># Log (RichTextBox)<br>$TxtLog = New-Object System.Windows.Forms.RichTextBox<br>$TxtLog.Location = \"40,$CurrentY\"; $TxtLog.Size = \"640,320\"; $TxtLog.ReadOnly = $true; $TxtLog.BackColor = \"Black\"; $TxtLog.ForeColor = \"SpringGreen\"; $TxtLog.Font = $FontLog<br>$Form.Controls.Add($TxtLog)<br><br># --- Create proccess ---<br>$BtnCreate.Add_Click({<br>    $TxtLog.Clear()<br>    if ([string]::IsNullOrWhiteSpace($TxtCN.Text) -or [string]::IsNullOrWhiteSpace($TxtPass.Text)) { <br>        [void][System.Windows.Forms.MessageBox]::Show(\"Please fill CN and Password!\"); return <br>    }<br><br>    $CN = $TxtCN.Text<br>    $OutPath = \"$env:USERPROFILE\\Desktop\\Certs_$($CN)\"<br>    if (-not (Test-Path $OutPath)) { New-Item -ItemType Directory -Path $OutPath }<br><br>    try {<br>        Write-Log \"&gt;&gt; Starting generation for $CN...\"<br>        <br>        # DnsName CN + SAN<br>        $DnsList = @($CN)<br>        if (![string]::IsNullOrWhiteSpace($TxtSAN.Text)) {<br>            $DnsList += $TxtSAN.Text -split ',' | ForEach-Object { $_.Trim() }<br>        }<br><br>        $CertParams = @{<br>            Subject = \"CN=$CN\"<br>            DnsName = $DnsList<br>            NotAfter = $DateExp.Value<br>            CertStoreLocation = \"Cert:\\LocalMachine\\My\"<br>            KeyExportPolicy = \"Exportable\"<br>            Provider = \"Microsoft Software Key Storage Provider\"<br>        }<br><br>        # Sign with CA <br>        if ($ComboCAs.SelectedIndex -gt 0) {<br>            $thumb = ($ComboCAs.SelectedItem -split \"\\[\")[-1].Replace(\"]\", \"\")<br>            $CertParams.Add(\"Signer\", (Get-Item \"Cert:\\LocalMachine\\My\\$thumb\"))<br>            Write-Log \"[INFO] Signed by CA: $($ComboCAs.SelectedItem)\"<br>        }<br><br>        # Setting<br>        if ($ComboType.SelectedItem -eq \"Root CA\") { $CertParams.Add(\"KeyUsage\", \"CertSign\") }<br><br>        # Create<br>        $NewCert = New-SelfSignedCertificate @CertParams<br>        Write-Log \"[V] Success: Certificate created in Store.\"<br><br>        # Export<br>        Export-AsPfx -Cert $NewCert -FilePath \"$OutPath\\$CN\" -Password $TxtPass.Text<br>        Export-Certificate -Cert $NewCert -FilePath \"$OutPath\\$CN.cer\"<br>        <br>        Write-Log \"[V] PFX &amp; CER exported to Desktop.\" ([System.Drawing.Color]::Cyan)<br>        explorer.exe $OutPath<br><br>    } catch {<br>        Write-Log \"[X] ERROR: $($_.Exception.Message)\" ([System.Drawing.Color]::Red)<br>    }<br>})<br><br>$Form.ShowDialog()<br><\/pre>\n\n\n\n<p class=\"has-vivid-cyan-blue-color has-text-color has-link-color wp-elements-7e93a090b3648ba86e52737a4ef17825\">You can download from here : <strong><a href=\"https:\/\/itsimple.info\/wp-content\/uploads\/2026\/03\/CertCreator.ps1_.txt\">CertCreator.ps<\/a>1<\/strong>  (change the file from TXT to PS1)<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes for developer needs. You want to create a Certificates which will implement HTTPS or code sighing, I have created a Powershell Script that have a simple GUI and create Certificates for all kind of needs, this is the script : Add-Type -AssemblyName System.Windows.FormsAdd-Type -AssemblyName System.Drawing# &#8212; Core Function &#8212;# Get CA cert from local [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21,22,4,12,14,15],"tags":[],"class_list":["post-3126","post","type-post","status-publish","format-standard","hentry","category-operating-systems","category-security","category-tech","category-tutorials","category-windows","category-windows-server"],"_links":{"self":[{"href":"https:\/\/itsimple.info\/index.php?rest_route=\/wp\/v2\/posts\/3126","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itsimple.info\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itsimple.info\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itsimple.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itsimple.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3126"}],"version-history":[{"count":3,"href":"https:\/\/itsimple.info\/index.php?rest_route=\/wp\/v2\/posts\/3126\/revisions"}],"predecessor-version":[{"id":3131,"href":"https:\/\/itsimple.info\/index.php?rest_route=\/wp\/v2\/posts\/3126\/revisions\/3131"}],"wp:attachment":[{"href":"https:\/\/itsimple.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3126"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itsimple.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3126"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itsimple.info\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3126"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}