Powershell - bulk decryption of files

Copper Contributor

Hi all,

 

Hope someone with some scripting skills can help here.

 

I'm using openssl to encrypt and decrypt files. I can decrypt single files via command line but the problem comes when I'm trying to bulk decrypt using a wildcard like *.crypt in the command line doesn't work. 

 

openssl.exe cms -decrypt -inkey C:/key.pem -recip C:/cert.pem -inform DER -in "E:/*.crypt" -out" E:/*.xml"

 

I'm unable to find a parameter in openssl to do a bulk decrypt so I thought hey I'll use powershell to decrypt each file, maybe something like

 

$file = *.crypt

for each file in C:\folder\*.crypt

     { 

      <run command> $file

      }

 

can anyone help with how I can script this in PS or point me in the right direction. Or even tell me if this is even possible.

 

Thanks

 

1 Reply

@Chi_L 

 

Hi, Chi.

 

This is a bit late but may help someone with a similar question.

 

This simple one-liner (spread out a bit for readability) would likely suffice.

 

(Get-ChildItem -Path "D:\Data\*.crypt").FullName | % {
    openssl.exe cms -decrypt -inkey C:\key.pem -recip C:\cert.pem -inform DER -in "$_" -out "$($_ -replace '\.crypt$', '.xml')";
}