[fpc-pascal] Blowfish encryption: What I´m doing wrong?
Peter
peter at pblackman.plus.com
Wed Apr 25 12:21:29 CEST 2018
On 25/04/18 03:56, 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
> if length(Value) = 0 then
> begin
> Result := '';
> Exit;
> end;
> try
> stream := TStringStream.Create('');
> en := TBlowFishEncryptStream.Create(FKey, stream);
> en.Write(Value[1], Length(Value));
> Result := stream.DataString;
> finally
> FreeAndNil(en);
> FreeAndNil(stream);
> end;
> end;
>
> function TBlowFishCripto.Decrypt(const encrypted: string;
> out decrypted: string): boolean;
> var
> de: TBlowFishDeCryptStream;
> s2: TStringStream;
> decr: string;
> begin
> if length(encrypted) = 0 then
> begin
> Result := True;
> decrypted := '';
> Exit;
> end;
>
> { 4 }
> s2 := TStringStream.Create(encrypted);
> { 5 }
> de := TBlowFishDeCryptStream.Create(FKey, s2);
> { 6 }
> decr := de.ReadAnsiString;
>
> de.Free;
> s2.Free;
>
> decrypted:=decr;
> REsult:=true;
>
> FreeAndNil(de);
> FreeAndNil(s2);
> end;
>
> When the method Decrypt runs with a argument 'encrypted' with a string
> returned by the method Encrypt, it raise an exception 203 on line
> after {6}
> I don´t know how to debug this.
>
> --
> /Timeo hominem unius libri/
>
> []s
> Guionardo Furlan
> http://www.guionardofurlan.com.br
>
>
> _______________________________________________
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Hi,
Has your "FKey" been properly created and initialised?
Regards,
Peter B
More information about the fpc-pascal
mailing list