[fpc-pascal] Re: encryption and decryption

silvioprog silvioprog at gmail.com
Sat Jun 23 18:28:38 CEST 2012


2012/6/23 leledumbo <leledumbo_cool at yahoo.co.id>:
>> How to use TBlowFishEnCryptStream? Is there any example for mortals?
>
> No but I guess the doc is clear enough.
>
> To encrypt:
> 1. Create TBlowFishEnCryptStream instance supplying a key and the stream to
> write encrypted data to
> 2. Write the data using its Write method
> 3. Flush or Free (Free implies Flush) to ensure all data are written
>
> To decrypt:
> 1. Create TBlowFishDeCryptStream instance supplying a key and the stream
> containing previously encrypted data. If you want to use directly previous
> stream, ensure to Seek it to the first data. To be safe, create a new stream
> instead and put the data from previous stream.
> 2. Read the data using its Read method (you should now the data length, for
> some stream Size property can be used)
>
> An example:
>
> {$mode objfpc}{$H+}
>
> uses classes,blowfish;
>
> var
>  en: TBlowFishEncryptStream;
>  de: TBlowFishDeCryptStream;
>  s1,s2: TStringStream;
>  key,value,temp: String;
> begin
>  key := 'testkey';
>  value := 'this is a string';
>
>  s1 := TStringStream.Create('');
>  en := TBlowFishEncryptStream.Create(key,s1);
>    en.Write(value[1],Length(value));
>  en.Free;
>
>  WriteLn('encrypted: ' + s1.DataString);
>
>  s2 := TStringStream.Create(s1.DataString);
>  s1.Free;
>
>  de := TBlowFishDeCryptStream.Create(key,s2);
>
>  SetLength(temp,s2.Size);
>  de.Read(temp[1],s2.Size);
>  WriteLn('decrypted: ' + temp);
>  de.Free;
>
>  s2.Free;
> end.
>
> --
> View this message in context: http://free-pascal-general.1045716.n5.nabble.com/encryption-and-decryption-tp5710131p5710137.html
> Sent from the Free Pascal - General mailing list archive at Nabble.com.

I'll test this sample now ... :)

-- 
Silvio Clécio
My public projects - github.com/silvioprog



More information about the fpc-pascal mailing list