[fpc-pascal] Blowfish encryption: What I´m doing wrong?

Michael Van Canneyt michael at freepascal.org
Wed Apr 25 12:27:11 CEST 2018



On Tue, 24 Apr 2018, Guionardo Furlan wrote:

> Hello guys
>
> I´ve a single code to encrypt/decrypt strings using Blowfish.
>
> function TBlowFishCripto.Encrypt(const Value: string): string;
> var
>  en: TBlowFishEncryptStream;
>  stream: TStringStream;
> begin
>
>   { 4 }
>  s2 := TStringStream.Create(encrypted);
>  { 5 }
>  de := TBlowFishDeCryptStream.Create(FKey, s2);
>  { 6 }
>  decr := de.ReadAnsiString;

You can only read an ansistring that was written with WriteAnsistring.
This is not the case here. You must either use WriteAnstring when writing,
or read the max available bytes yourself.

Michael.


More information about the fpc-pascal mailing list