Stream support ? - WeOnlyDo Discussion board

Stream support ? (wodCrypt)

by dandraka, Monday, November 07, 2005, 17:36 (4395 days ago)

Hi,

We are using wodCrypt for an application of ours, and we have the following problem:

It seems that, in order to decrypt a file the component needs to load it all in memory first. And while the encryption/decryption is done correctly, this causes huge delays: a typical file is about 20-30MB, and a typical user has about 128-256 of memory. So loading all 30MB in memory causes extensive disk swapping.

Is there a way to implement your component withing a FileStream ?

Below is a code snippet, example of how we use wodCrypt (Delphi 7):

Function DecryptFile(Const Source,Destination: String): Integer;
Const
SKey = 'myProgKey';
LKey = 'myLicense';
Var
CryptObject: TWodCryptCom;
SourceBlob, DestinationBlob : TWodMemBlob;
SBlob, DBlob : IBlob;
Begin
Try
Try
CoInitialize(nil);
SourceBlob := WODCRYPTCOMLib_TLB.TwodMemBlob.Create(nil);
DestinationBlob := WODCRYPTCOMLib_TLB.TwodMemBlob.Create(nil);
SourceBlob.FromFile(Source);
SourceBlob.DefaultInterface.QueryInterface(WODCRYPTCOMLib_TLB.IID_IBlob, SBlob);
DestinationBlob.DefaultInterface.QueryInterface(WODCRYPTCOMLib_TLB.IID_IBlob, DBlob);
CryptObject := TwodCryptCom.Create(nil);
With CryptObject Do Begin
LicenseKey := LKey;
Optimized := False;
type_ := Blowfish;
SecretKey := SKey;
Decrypt(SBlob, DBlob);
End;
DestinationBlob.ToFile(Destination);
Finally
FreeAndNil(DestinationBlob);
FreeAndNil(SourceBlob);
FreeAndNil(CryptObject);
End;
Result := NO_ERROR;
Except
Result := ERROR;
End;
End;

Re: Stream support ?

by wodSupport, Monday, November 07, 2005, 18:53 (4395 days ago) @ dandraka

Dandraka,

makes sense what you suggest. I'm just not sure if this would be easy to add.

Why don't you save file to a disk? If you don't compress it, it will be loaded on demand.

Re: Stream support ?

by mf, Tuesday, November 08, 2005, 09:53 (4394 days ago) @ wodSupport

Well I am not sure what you mean by saving it to a file. As you can see we are already saving the encoded or decoded blob to a file.

The problem is that we have a great delay in encoding or decoding a file of the size of about 30 or 40MB. I believe that the blob component loads all its data to memory that causes that delay.

Do you have any suggestions about this time problem, or explain better what you mean by saving it to file, which from my point of view is already done from us.

Re: Stream support ?

by wodSupport, Tuesday, November 08, 2005, 13:48 (4394 days ago) @ mf

I understand what you need, I think. Instead of one big delay, you thought that encryption during transport would be better since those small delays wouldn't even be noticed.

Unfortunatelly, wodCrypt can't do it at present. I will review the code to see if streaming can be added, but can't promise anything at this point.

Kreso

Re: Stream support ?

by dandraka, Wednesday, November 09, 2005, 11:12 (4393 days ago) @ wodSupport

Instead of one big delay, you thought that encryption during transport would be better since those small delays wouldn't even be noticed.

No, that's not it.

The problem is that, in order to decrypt (or encrypt) the file, we have to load it all in memory first. The big delay is due to the OS using its virtual memory (swap file), because the memory is not enough.

Re: Stream support ?

by wodSupport, Wednesday, November 09, 2005, 11:22 (4393 days ago) @ dandraka

Yes, but I see in your code you used MemBlob. Why didn't you use FileBlob instead?

MemBlob uses memory, FileBlob uses file..

Re: Stream support ?

by dandraka, Wednesday, November 09, 2005, 11:25 (4393 days ago) @ wodSupport

To supplement the above: We do need the encryption/decryption done all at once; the file we need is a database, so there's no point in having, say, half of it encrypted (or decrypted).

We just need to do this using the disk file, and not having to load the whole file in memory first.

As you can see from the 1st post's code, we are using TWodMemBlob. If we use TWodFileBlob, is this going to do the trick ? Or will it be the same ?

Re: Stream support ?

by wodSupport, Wednesday, November 09, 2005, 11:26 (4393 days ago) @ dandraka

That was just my suggestion. Yes, try using FileBlob instead.