Created
February 16, 2023 04:24
-
-
Save dentolos19/803820c8b305224db8167e6d5b158691 to your computer and use it in GitHub Desktop.
This file contains 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
Set-Location $PSScriptRoot | |
Write-Host "PFX Certificate Creator" | |
Write-Host "" | |
Write-Host "Create a PFX certificate for use with MSIX Package Signing." | |
Write-Host "" | |
$subjectName = Read-Host "Subject Name" | |
$friendlyName = Read-Host "Friendly Name" | |
$certificateKey = Read-Host "Certificate Key" -AsSecureString | |
$certificateStore = "Cert:\CurrentUser\My" | |
New-SelfSignedCertificate ` | |
-Type Custom ` | |
-Subject "CN=$subjectName" ` | |
-KeyUsage DigitalSignature ` | |
-FriendlyName $friendlyName ` | |
-CertStoreLocation $certificateStore ` | |
-TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.3", "2.5.29.19={text}") | ` | |
Out-Null | |
$certificate = Get-ChildItem $certificateStore | ` | |
Where-Object { $_.Subject -eq "CN=$subjectName" -and $_.FriendlyName -eq $friendlyName } | ` | |
Select-Object -First 1 | |
Export-PfxCertificate -Cert $certificate -FilePath "$friendlyName.pfx" -Password $certificateKey | Out-Null | |
$bytes = [System.IO.File]::ReadAllBytes("$PSScriptRoot\$friendlyName.pfx") | |
$text = [System.Convert]::ToBase64String($bytes) | |
[System.IO.File]::WriteAllText("$PSScriptRoot\$friendlyName.pfx.txt", $text) | |
Get-ChildItem "$certificateStore\$($certificate.Thumbprint)" | Remove-Item | |
Write-Host "" | |
Write-Host "PFX Certificate created successfully!" | |
Write-Host "Saved To: $PSScriptRoot\$friendlyName.pfx" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment