Curated Examples
Generate a PGP key pair
Use PSPGP to create public and private PGP key files.
This pattern is useful when a workflow needs dedicated PGP keys for encrypted file exchange.
It is adapted from the source example at Examples/Example-GeneratePGP.ps1.
When to use this pattern
- You need a project-specific PGP key pair.
- The public key will be shared with another party.
- The private key and password will be stored securely outside the script.
Example
Import-Module PSPGP
$keyFolder = Join-Path $PSScriptRoot 'Keys'
New-Item -ItemType Directory -Force -Path $keyFolder | Out-Null
New-PGPKey `
-HashAlgorithm Sha512 `
-FilePathPublic "$keyFolder\PublicPGP.asc" `
-FilePathPrivate "$keyFolder\PrivatePGP.asc" `
-UserName 'automation@example.com' `
-Password '<store-this-securely>'
What this demonstrates
- creating a public/private key pair
- choosing a hash algorithm
- keeping file paths explicit for later automation steps