Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2015-12

Cryptography with Blowfish

2 messages · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

luciano de souza

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

Reply by email

luciano de souza
to luciano de souza

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 :

Show quoted text 33 lines
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

Reply by email