Encoding chunks

42 views
Skip to first unread message

tony medeiros

unread,
Nov 1, 2011, 4:49:37 PM11/1/11
to python-gnupg
Hi, I am interested in using gnupg to encode an incoming stream and
output the cipher text while still streaming the plain text.
For example:t P = p1 + p2, + p3; C = gpg_encrypt(P)
How can I use gnupg such that

C = gpg_encrypt(p1) + gpg_encrypt(p2) + gpg_encrypt(p3)

My goal is to intercept a network stream, encode it in gpg, then
continue sending it on its path. I only have access to one chunk at a
time.

Where I am confused is when using gpg.encrypt_file(stream). What is
this returning? Is expecting to encrypt a whole file or just up to the
end of the stream, so the next time I call encrypt_file(stream) it
will continue where it left off.

Do you guys have any suggestions in doing with only keeping
size(chunk) in memory at one time?

Thanks
Tony

Vinay Sajip

unread,
Nov 7, 2011, 5:09:27 AM11/7/11
to python-gnupg
> Where I am confused is when using gpg.encrypt_file(stream). What is
> this returning? Is expecting to encrypt a whole file or just up to the
> end of the stream, so the next time I call encrypt_file(stream) it
> will continue where it left off.

If you pass encrypt_file a file-like object, then it should work as
you expect, but with a single encrypt_file call rather than multiple
calls. The encrypted stream should be streamed out to gpg's stdout,
which is picked up by the Python code and buffered in memory: if you
want to do this differently (e.g. only keep some parts of the
encrypted file in memory at a time) you will need to handle this
yourself by subclassing GPG. Take a look at the source code to see how
stdout data from gpg is being handled.

Regards,

Vinay Sajip
Reply all
Reply to author
Forward
0 new messages