[fpc-pascal] Cryptography with Blowfish

luciano de souza luchyanus at gmail.com
Tue Dec 1 21:48:29 CET 2015


Problem solved. A friend advert me to the fact I can't use the  same
TMemoryStream for input and output.

This is the correct code:

program test;
{$mode objfpc}{$H+}

uses
blowfish, classes;

var
VInput, VOutput: TMemoryStream;
VCypher: TBlowfishEncryptStream;
BEGIN
VInput := nil;
VOutput := TMemoryStream.create;
VCypher := TBlowfishEncryptStream.create('lazarus-br', VOutput);
try
VInput := TMemoryStream.create;
VInput.LoadFromFile('origin.txt');
VCypher.writebuffer(VInput.memory, VInput.size);
VOutput.SaveToFile('output.bfe');
finally
VCypher.free;
VInput.free;
VOutput.free;
end;
END.

2015-12-01 17:57 GMT-02:00, luciano de souza <luchyanus at gmail.com>:
> Hello all,
>
> What's wrong with this code?
>
> I try to cryptograph a file. The compiler doesn't raise errors, but
> after running the program, no results happen.
>
> program test;
> {$mode objfpc}{$H+}
>
> uses
> blowfish, classes;
>
> var
> VMemory: TMemoryStream;
> VCypher: TBlowfishEncryptStream;
> BEGIN
> VMemory := TMemoryStream.create;
> VMemory.LoadFromFile('origin.txt');
> VCypher := TBlowfishEncryptStream.create('lazarus-br', VMemory);
> try
> VMemory.position := 0;
> VCypher.write(VMemory.memory, VMemory.size);
> VMemory.SaveToFile('output.bfe');
> finally
> VCypher.free;
> VMemory.free;
> end;
> END.
>
> --
> Luciano de Souza
>


-- 
Luciano de Souza



More information about the fpc-pascal mailing list