Sec has asked for the wisdom of the Perl Monks concerning the following question:

Is there a way to pull a file out of a password-protected ZIP file in perl? I searched CPAN for modules, but it appears that all of them lack password functionality. As I don't want to reinvent the wheel: Does anyone have a solution at hand? And if not, how would you approach the problem? As I am running on unix, i can probably fake it by calling the unzip command.

Replies are listed 'Best First'.
Re: Unzip with password?
by kennethk (Abbot) on Feb 19, 2009 at 01:11 UTC
    Easy, non-Perl solution: `unzip -P $password $archive $file`, where you may want to take precautions on how you encode $password. The lack of password support is likely because ZIP encryption has a known vulnerability.
Re: Unzip with password?
by Anonymous Monk on Feb 19, 2009 at 04:02 UTC
Re: Unzip with password?
by Sec (Monk) on Apr 01, 2009 at 15:05 UTC
    As there is no appopriate perl module, I'm now doing it this way:
    my $r; { open(ZIP,"-|","/usr/local/bin/unzip -P '·······' -p cache/$zipname $fname") || die "unzip failure"; local($/)=undef; $r=<ZIP>; close(ZIP); };
    Of course you need to make sure that $zipname and $fname contain no evil characters.
      Of course you need to make sure that $zipname and $fname contain no evil characters.

      You don't if you use the array form of open:

      open(ZIP,"-|","/usr/local/bin/unzip" => -P => '·······', -p => "cache/$zipname", $fname, ) || die "unzip failure";