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

Is there any way to take buffered chunks of input read from a file posted via CGI, encrypt them with Crypt-OpenPGP say 1024 bytes at a time and then write the encrypted pieces out to disk a piece at a time rather than having to load the entire file into memory and encrypt the whole thing at once? I need to support PGP encrypting files no larger than 50mb, but when I try to encrypt a file this size it keeps killing the process. So, I'm wondering if there is a way possibly to encrypt a file without having the whole thing available all at once?

Replies are listed 'Best First'.
Re: Using OpenPGP to encrypt large files
by pc88mxer (Vicar) on Aug 05, 2008 at 16:30 UTC
    From what I can tell, Crypt::OpenPGP does not support streaming. Even if you pass it a file name, the very first thing it does is slurp the contents into a variable.

    What about piping your data to a command-line version of PGP? I.e., something like:

    open(PGP, "|gpg -output file -encrypt -recipient ..."); while (<FH>) { print PGP } close(PGP);