Project

PSPGP

PSPGP is a PowerShell module that provides PGP functionality in PowerShell. It allows encrypting and decrypting files/folders and strings using PGP.

Stars72
Forks23
Open issues1
PowerShell Gallery downloads3814786
Releasev1.0.0
Language: C# Updated: 2026-04-07T08:35:39.0000000+00:00

Curated Examples

Encrypt and decrypt a string

Use PSPGP to protect a string and decrypt it with the matching private key.

This pattern is useful when a script has to pass a protected payload between two controlled steps.

It is adapted from the source examples at Examples/Example-EncryptString.ps1 and Examples/Example-DecryptString.ps1.

When to use this pattern

  • You need to encrypt text with a public key.
  • The matching private key is available only to the decrypting side.
  • You want a small smoke test before encrypting files or folders.

Example

Import-Module PSPGP

$publicKey = "$PSScriptRoot\Keys\PublicPGP.asc"
$privateKey = "$PSScriptRoot\Keys\PrivatePGP.asc"

$protectedString = Protect-PGP -FilePathPublic $publicKey -String 'This is a string to encrypt'

Unprotect-PGP `
    -FilePathPrivate $privateKey `
    -Password '<private-key-password>' `
    -String $protectedString

What this demonstrates

  • encrypting with the public key
  • decrypting with the private key
  • keeping key paths explicit in the workflow

Source