This script for Windows PowerShell will decrypt a PGP encrypted (and armored) string using your PGP private key and passphrase.
This script uses BouncyCastle.NetFramework (also bc-chsarp).
The PowerShell snippet below will make the script available in the current PowerShell session.
The first time you run PGPDecrypt-Message it will install BouncyCastle.NetFramework.
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12
iex (irm https://raw.githubusercontent.com/nstevens1040/PGPDecrypt-Message/main/PGPDecrypt-Message.ps1)
NAME
PGPDecrypt-Message
SYNTAX
PGPDecrypt-Message [-pgp_encrypted_message] <string> [-pgp_private_key] <string> [[-private_key_passphrase] <string>] [<CommonParameters>]
PARAMETERS
-pgp_encrypted_message <string>
Required? true
Position? 0
Accept pipeline input? false
Parameter set name (All)
Aliases None
Dynamic? false
-pgp_private_key <string>
Required? true
Position? 1
Accept pipeline input? false
Parameter set name (All)
Aliases None
Dynamic? false
-private_key_passphrase <string>
Required? false
Position? 2
Accept pipeline input? false
Parameter set name (All)
Aliases None
Dynamic? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
None
OUTPUTS
System.Object
ALIASES
None
REMARKS
None
(private key is a throwaway)
PGPDecrypt-Message -pgp_encrypted_message @"
-----BEGIN PGP MESSAGE-----
Version: BCPG C# v1.8.10.0
owJ4nAHkARv+hQGMAzQrCxerEdDLAQwA5KLnXJT/MPZ1OjqeQTouGjSgu2jPDENS
8NAJDGA7UyddjI672VbE2PyRqWyFT9Np3mnMxfLu/32mtrSZA7YF2sZ3bc8hFgha
UAnDr0+BhGzGign9Kp/iDnoh8RIc72ooStLXwLlKiAzDqMQ8npU2B4RyhwUM0MFC
c0+NjZBEHFRG7JavJ9FPdF3W9G0KMOPQVTPZghiP/zgM/2Ji8nH5vSSldIebhvj4
M85RHUwWKDnDqjymiklrR1Necc3H6bOW6if3U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