Lorenzo wrote:

> I have a quick question to ask. I'm using the EVP_EncryptInit and 
> EVP_DecryptInit functions to stream data to a file. Basically, I 
> encrypt data , one byte at a time, which is in the put area of my 
> filebuf object and send it out. I When I get data from the file, I 
> decrypt each byte I receive one byte at a time. The problem is when i 
> use 'seekg(x)' to seek to a point in the file , when I try to decrypt 
> the buffer I get back, the results are wrong. However, when I start 
> from the beginning, every thing is fine. When I seek, it does seek to 
> the right byte in the file. Does any one know why this may be the case?
>
Ecryption does (usually) not encrypt each byte independently from all 
the others. The encryption of a byte in the stream depends on what was 
done before. So, seeking to a different position in the file gets the 
encryption routines out of sync and you get garbage.
 You have to read all data....
If you want your applicatoin to use a seek command, have a look at the 
BIOs in OpenSSL (an abstraction of I/O-Operations). BIOs can be layered 
and perform some kind of filtering (e.g. RC4 encryption/decryption). And 
they provide a BIO_seek() command. I havn't tried it myself, but I 
assume it does the right stuff.

Jörg




______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [EMAIL PROTECTED]
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to