Boys, for a project he's making a cryptography library with 4 functions
2 for encryption / decryption of files
2 for encryption / decryption of strings
File no problem, they do not work with strings. About me explain why?
unit Unit_Crypt_Function;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, DCPSha1, DCPcrypt2, DCPblockciphers, DCPblowfish, dcprijndael;
type
{ TCyperFile }
TCyperFile=class
public
constructor Create;
destructor Free;
procedure CifraFile(Original:String;Encrypted:String;Password:String; Password2: string);
procedure DeCifraFile(Encrypted:String;Original:string;Password:String; Password2: string);
function CifraStringa(Original: String;Password:String; Password2: string): string;
function DeCifraStringa(Original: String;Password:String; Password2: string): string;
end;
implementation
{ TCyperFile }
constructor TCyperFile.Create;
begin
end;
destructor TCyperFile.Free;
begin
end;
procedure TCyperFile.CifraFile(Original:String;Encrypted:String;Password:String; Password2: string);
var
BlowFish:TDCP_Blowfish;
AES: TDCP_rijndael;
OriginalStream:TFileStream;
EncryptStream:TFileStream;
begin
AES:=TDCP_rijndael.Create(nil);
AES.InitStr(Password2,TDCP_Sha1);
BlowFish := TDCP_Blowfish.Create(nil);
BlowFish.InitStr(Password,TDCP_Sha1);
OriginalStream := TFileStream.Create(Original,fmOpenRead);
EncryptStream := TFileStream.Create(Encrypted,fmCreate);
Blowfish.EncryptStream(OriginalStream,EncryptStream,OriginalStream.Size);
BlowFish.Burn;
AES.EncryptStream(EncryptStream,EncryptStream,EncryptStream.Size);
AES.Burn;
EncryptStream.Free;
OriginalStream.Free;
Blowfish.Free;
AES.Free;
end;
procedure TCyperFile.DeCifraFile(Encrypted:String;Original:string;Password:String; Password2: string);
var
BlowFish:TDCP_Blowfish;
AES: TDCP_rijndael;
DecryptStream:TMemoryStream;
EncryptStream:TFileStream;
begin
AES:=TDCP_rijndael.Create(nil);
AES.InitStr(Password2,TDCP_Sha1);
BlowFish := TDCP_Blowfish.Create(nil);
BlowFish.InitStr(Password,TDCP_Sha1);
EncryptStream := TFileStream.Create(Encrypted,fmOpenRead);
DecryptStream := TMemoryStream.Create;
Blowfish.DecryptStream(EncryptStream,DecryptStream ,EncryptStream.Size);
Blowfish.Burn;
AES.DecryptStream(DecryptStream,DecryptStream,DecryptStream.Size);
AES.Burn;
EncryptStream.Free;
DecryptStream.Position :=0;
DecryptStream.SaveToFile(Original);
DecryptStream.Free;
AES.Free;
end;
function TCyperFile.CifraStringa(Original: String; Password: String; Password2: string): string;
var
BlowFish:TDCP_Blowfish;
AES: TDCP_rijndael;
ret: string;
begin
ret:='';
AES:=TDCP_rijndael.Create(nil);
AES.InitStr(Password2,TDCP_Sha1);
BlowFish := TDCP_Blowfish.Create(nil);
BlowFish.InitStr(Password,TDCP_Sha1);
ret:=Blowfish.EncryptString(Original);
BlowFish.Burn;
ret:=AES.EncryptString(ret);
AES.Burn;
Blowfish.Free;
AES.Free;
result:=ret;
end;
function TCyperFile.DeCifraStringa(Original: String; Password: String; Password2: string): string;
var
BlowFish:TDCP_Blowfish;
AES: TDCP_rijndael;
ret: string;
begin
ret:='';
AES:=TDCP_rijndael.Create(nil);
AES.InitStr(Password2,TDCP_Sha1);
BlowFish := TDCP_Blowfish.Create(nil);
BlowFish.InitStr(Password,TDCP_Sha1);
ret:=Blowfish.DecryptString(Original);
BlowFish.Burn;
ret:=AES.DecryptString(ret);
AES.Burn;
Blowfish.Free;
AES.Free;
result:=ret;
end;
end.