PSrookie
PSrookie

Reputation: 17

Powershell fails at pgp decryption

I am trying to decrpyt the automated pgp message with powershell however it drops an error message: "gpg: decrypt_message failed: No such file or directory"

The sign and encryption part was done with command line commands:

$path = "\\networkdrive\folder1\message"
$step2files = Get-ChildItem -Recurse -Path $path | Where-Object{$_.Extension -eq ".asc"}
$z=1
foreach ($files in $step2files) {
    $outputname = "$files.pgp"
    $input = $files
    $z 

    $options = " --output $outputname –-encrypt --recipient XYKey $files"
    $options

    gpg  --output $outputname --encrypt --recipient XYKey $input
    $z++
}

I need the response decrypted in a similar way and even though powershell finds all the respective files, the aforementioned error message displays.

The codepart is:

$extracted = "\\networkdrive\folder1\extracted"
$step5files = Get-ChildItem -Recurse -Path $extracted | Where-Object{$_.Extension -eq ".pgp"}
$z=1
foreach ($files in $step5files) {
    $outputname = "$files.xml"
    $input = $files
    $z 

    $options = " -u KeyID --batch --yes --passphrase password --output $outputname --decrypt $files"
    $options

    gpg  -u KeyID --batch --yes --passphrase password --output $outputname --decrypt $input
    $z++
}

Any idea?

Upvotes: 0

Views: 1210

Answers (1)

Mike Twc
Mike Twc

Reputation: 2355

I'm using latest GnuPG, this works fine on my end:

 $cipher =  "My secret message"  | gpg -ear 'MyRecipient'

 Write-Host $chipher 

 $message = $cipher | gpg --batch --yes --passphrase 'MyPassphrase'

 Write-Host $message

Upvotes: 1

Related Questions