EldoS | Feel safer!

Software components for data protection, secure storage and transfer

OpenPGP Streaming

Also by EldoS: CallbackFilter
A component to monitor and control disk activity, track file and directory operations (create, read, write, rename etc.), alter file data, encrypt files, create virtual files.
#7846
Posted: 10/13/2008 05:45:16
by Allister Green (Standard support level)
Joined: 10/10/2008
Posts: 6

I have been able to encrypt and decrypt if I load the complete message into a memory stream before doing the encryption or decryption.

However, I want to be able to stream the encryption / decryption, i.e. do the following until all the source data has been read:
- Read a fixed number of bytes from the source,
- Encrypt / decryt thse bytes only,
- Write the encrypted / decrypted data to the destination file.

Reference encryption, I am going this using the pgpWriter.Encrypt method, and specifying number of bytes that should be read each time as the third parameter.
This produces an encrypted file, hence seems to work.

However, when I go to decrypt the file, on the first call to pgpReader.DecryptAndVerify I get the error "unexpected end of packet".

Instead of using the TElPGPWriter and TElPGPReader libraries, I have also tried using the TElPGPEncryptingStream TElPGPDecryptingStream libraries, calling the ProcessStream method, but get exactly the same result.

I am assuming that this is an issue around block size being encrypted and decrypted at a time.

Has anyone done this before? I would reall appreciate any guidance.

I appologise if there is already a forum on this, but my search didn't find any.

Thanks,

Allister.
#7847
Posted: 10/13/2008 06:00:06
by Ken Ivanov (EldoS Corp.)

Thank you for contacting us.

One of the possible ways to resolve your task is to create a descendant of System.IO.Stream class and override its reading-related methods and properties (Read(), Length, CanRead) according to the specifics of your data source. This will allow you to respond to TElPGPReader's read requests, returning the data to be encrypted once it is available.
#7848
Posted: 10/13/2008 08:15:29
by Allister Green (Standard support level)
Joined: 10/10/2008
Posts: 6

Quote
Innokentiy Ivanov wrote:
Thank you for contacting us.

One of the possible ways to resolve your task is to create a descendant of System.IO.Stream class and override its reading-related methods and properties (Read(), Length, CanRead) according to the specifics of your data source. This will allow you to respond to TElPGPReader's read requests, returning the data to be encrypted once it is available.


Thanks for the reply.

I have done this and still am getting the same result (my overridden Read method of my stream class is calling the pgpWriter.Encrypt(streamInput, streamOutput, numberOfBytesToRead) )

I have made some progress. I am using a 2048 bit key to encrypt and decrypt.
- When I encrypt by reading and encrypting 341 bytes at a time (pgpWriter.Encrypt(streamInput, streamOutput, 341); ), 923 bytes are produced in the output stream.
- If I then decrypt by reading 923 bytes at a time, it works successfully.

So how should I proceed?

Is there a mathematical relationship between the no of bits in the key, the number of bytes being encrypted, and the resultant number of encrypted bytes produced? If so, could one way forward be to calculate and read a specific number of bytes at a time when decrypting?

Thanks.



#7855
Posted: 10/14/2008 02:45:03
by Mykola Olshevsky (Basic support level)
Joined: 07/07/2005
Posts: 450

It will not work as you trying to do - .Encrypt() and .Decrypt() methods processes whole data stream, and decryption will not work correctly if you will give it data in chunks.
You should call .Encrypt() and .Decrypt() methods only once, for a whole file or whatever you are encrypting.

But, you can write your own descendant of System.IO.Stream, as Innokentiy wrote.

Btw, asymmetric key is used only to encrypt session key, with which data stream is encrypted.

Reply

Statistics

Topic viewed 1596 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!