# Encrypt and decrypt a string

Encrypt and decrypt a string on Evotec with practical examples, usage guidance, and reusable project workflows.

Project

PSPGP

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

[View on GitHub](https://github.com/EvotecIT/PSPGP) [Visit Website](#) [Releases](https://github.com/EvotecIT/PSPGP/releases/tag/v1.0.1) [Changelog](#) [Get package](https://www.powershellgallery.com/packages/PSPGP)

Stars**75**

Forks**23**

Open issues**1**

PowerShell Gallery downloads**3831376**

Release**v1.0.2**

Language: C# Updated: 2026-11-23

Curated Examples

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

```powershell
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

- [Example-EncryptString.ps1](https://github.com/EvotecIT/PSPGP/blob/v2-speedygonzales/Examples/Example-EncryptString.ps1)
- [Example-DecryptString.ps1](https://github.com/EvotecIT/PSPGP/blob/v2-speedygonzales/Examples/Example-DecryptString.ps1)

<!-- PowerForge markdown artifact sha256:4CE7174F671E80C77DF611CAC36F9FAE4A1CDE52EB71C0BF72D6CCE3DDDEF2B3 -->
