| [CmdletBinding()] |
| param( |
| [string]$ConfigDir = "" |
| ) |
| $ErrorActionPreference = "Stop" |
|
|
| if ([string]::IsNullOrWhiteSpace($ConfigDir)) { |
| $scriptRoot = Split-Path -Parent $MyInvocation.MyCommand.Path |
| if ([string]::IsNullOrWhiteSpace($scriptRoot)) { |
| $scriptRoot = "." |
| } |
| $ConfigDir = (Join-Path $scriptRoot "..\config") |
| } |
|
|
| if (-not (Test-Path $ConfigDir)) { |
| New-Item -ItemType Directory -Force -Path $ConfigDir | Out-Null |
| } |
|
|
| $publicKeyPath = Join-Path $ConfigDir "update-public-key.xml" |
| $privateKeyPath = Join-Path $ConfigDir "update-private-key.xml" |
|
|
| if (Test-Path $publicKeyPath) { |
| Write-Host "Keys already exist. Skipping generation." |
| exit 0 |
| } |
|
|
| Write-Host "Generating new RSA key pair for update manifest signing..." |
| $rsa = [System.Security.Cryptography.RSA]::Create(2048) |
| $privateKeyXml = $rsa.ToXmlString($true) |
| $publicKeyXml = $rsa.ToXmlString($false) |
|
|
| $publicKeyXml | Set-Content -Path $publicKeyPath -Encoding UTF8 |
| $privateKeyXml | Set-Content -Path $privateKeyPath -Encoding UTF8 |
|
|
| Write-Host "Keys generated successfully." |
| Write-Host "Public Key: $publicKeyPath" |
| Write-Host "Private Key (KEEP SECRET): $privateKeyPath" |
|
|