EvotecIT / PSPGP

PSPGP is a PowerShell module that provides PGP functionality in PowerShell. It allows encrypting and decrypting files/folders and strings using PGP.
MIT License
57 stars 21 forks source link

Encrypt to multiple public keys #2

Closed get-fooby closed 2 years ago

get-fooby commented 3 years ago

Hello, while I haven't extensively tested this, I don't think it can allow encrypting to multiple public keys. I understand it's totally do-able in PGP world - but is the script able to do this as is? Regards

PrzemyslawKlys commented 3 years ago

Don't see it as an option in https://github.com/mattosaurus/PgpCore

Probably requires opening an issue on it, and if they implement it - we'll just add it.

jlaprade-git commented 2 years ago

Per this post (https://githubhelp.com/mattosaurus/PgpCore/issues/18) encrypting to multiple keys should be possible with pgpcore >1.4

PrzemyslawKlys commented 2 years ago

You're correct - it seems to be as simple as changing FilePathPublic to [string[]] instead of [string] and modifying logic to just convert FilePathPublic to PublicKey (FileInfo).

https://github.com/EvotecIT/PSPGP/blob/e989676b37a6f624b25bb6d00154cea2443e3038/Public/Protect-PGP.ps1#L18-L27

image

jlaprade-git commented 2 years ago

It looks like this was pushed to master. I am attempting to encrypt a string using your examples but receiving an error

PS C:\keys> $String = Protect-PGP -FilePathPublic @("$PSScriptRoot\Keys\PublicPGP1.asc", "$PSScriptRoot\Keys\PublicPGP2.asc") -String "This is string to encrypt"

Protect-PGP : Cannot process argument transformation on parameter 'FilePathPublic'. Cannot convert value to type
System.String.
At line:1 char:39
+ ... ePathPublic @("$PSScriptRoot\Keys\PublicPGP1.asc", "$PSScriptRoot\Key ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Protect-PGP], ParameterBindingArgumentTransformationException
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,Protect-PGP
PrzemyslawKlys commented 2 years ago

Are you using github version or PSGallery one? I have not published anything yet.

From the error message it would seem you're using "old version"

function Test {
    [CmdletBinding()]
    param(
        [string] $Test
    )
}

Test -Test @("$PSScriptRoot\Keys\PublicPGP.asc", "$PSScriptRoot\Keys\PublicPGP2.asc")

You're applying array to a string, and new version takes array instead of string.