It works. This is only another example how to use dcrypt (jshand2010 question in first post)Sorry, I mistook your post for the original poster's.
you know when you spoke about adding clauses DCPr.... to the uses part??
you mentioned that i also need to go to project options etc.... at this stage. i am unsure to where to put the paths to those clauses.
please help
I don't use the LCL for it, but here is how I code using the library:
I add the following to uses:
DCPrijndael, DCPSha256
Then when loading data from a file (leaving out what I do with the data:
var
Crypt: TDCP_rijndael;
FileData: TFileStream;
Data: TStringStream;
begin
FileData := TFileStream.Create(Filename, fmOpenRead);
Crypt := TDCP_rijndael.Create(nil);
try
Crypt.InitStr(Self.Password, TDCP_sha256); // self-Password is the password used to save the file
Crypt.DecryptStream(FileData, Data, FileData.Size);
Crypt.Burn;
// I then use Data as if it was not encrypted
...
finally
FreeAndNil(Crypt);
FreeAndNil(Data);
FreeAndNil(FileData);
end;
to save a file I do the following:
var
Crypt: TDCP_rijndael;
FileData: TFileStream;
Data: TStringStream;
begin
FileData := TFileStream.Create(Filename, fmCreate);
Data := TStringStream.Create('');
Crypt := TDCP_rijndael.Create(nil);
try
// I write data out to a stream
...
// then using that stream, I encrypt it to a file
Crypt.InitStr(Self.Password, TDCP_sha256);
Crypt.EncryptStream(Data, FileData, Data.Size);
Crypt.Burn;
finally
FreeAndNil(Crypt);
FreeAndNil(Data);
FreeAndNil(FileData);
end;
function Codifica(chave:string; texto:string; nivel:integer):string; {$ifndef linux} stdcall; {$else} cdecl; {$endif} //Encode(key, text, level)
var
motor: TDCP_blowfish;
i: integer;
t: string;
begin
if nivel=0
then nivel:=1
else if nivel>2
then nivel:=2;
motor:=TDCP_blowfish.Create(nil);
t:=texto;
for i:=1 to nivel do begin
motor.InitStr(chave,TDCP_sha256);
t:=motor.EncryptString(t);
motor.Burn;
end;
result:=t;
motor.Free;
end;
function Decodifica(chave:string; codigo:string; nivel:integer):string; {$ifndef linux} stdcall; {$else} cdecl; {$endif} //Decode(key, text, level)
var
motor: TDCP_blowfish;
i: integer;
t: string;
begin
if nivel=0
then nivel:=1
else if nivel>2
then nivel:=2;
motor:=TDCP_blowfish.Create(nil);
t:=codigo;
for i:=1 to nivel do begin
motor.InitStr(chave,TDCP_sha256);
t:=motor.DecryptString(t);
motor.Burn;
end;
result:=t;
motor.Free;
end;