unit Verschluesselung;
interface
uses
{ The DCP Encryption components and the unit md5.pas need to be installed }
sysutils, DCPcrypt, Base64, RMD160, Blowfish, md5 ;
type
TVerschluesselung =
Class
private
FSecretKey :
string ;
BF: TDCP_blowfish;
RMD: TDCP_rmd160;
public
function rmd160 (AValue :
string) :
string ;
function md5 (AValue :
string) :
string ;
function Encrypt (AValue :
string) :
string ;
function Decrypt (AValue :
string) :
string ;
constructor Create (SecretKey :
string) ;
end ;
var
CommonSafe : TVerschluesselung ;
implementation
{ TVerschluesselung }
constructor TVerschluesselung.Create(SecretKey:
string);
begin
FSecretKey := md5 (rmd160 (SecretKey)) ;
end;
function TVerschluesselung.Decrypt(AValue:
string):
string;
begin
BF := TDCP_blowfish.Create(
nil);
BF.InitStr(FSecretKey);
// initialize the cipher with the key
Result := B64Decode (AValue) ;
BF.DecryptCFB(Result[1],Result[1],length(Result));
//lblDecrypted.caption := AValue ;
BF.Reset;
// we are using CFB chaining mode so we must reset after each block of encrypted/decrypts
BF.Burn;
BF.free ;
end;
function TVerschluesselung.Encrypt(AValue:
string):
string;
begin
BF := TDCP_blowfish.Create(
nil);
BF.InitStr(FSecretKey);
// initialize the cipher with the key
BF.EncryptCFB(AValue[1],AValue[1],length(AValue));
Result := B64Encode(AValue) ;
BF.Reset;
// we are using CFB chaining mode so we must reset after each block of encrypted/decrypts
BF.Burn;
BF.free ;
end;
function TVerschluesselung.md5(AValue:
string):
string;
begin
result := md5print (md5String (AValue)) ;
end;
function TVerschluesselung.rmd160(AValue:
string):
string;
var
s :
string ;
i : integer ;
HashDigest:
array[0..31]
of byte;
begin
RMD := TDCP_rmd160.Create(
nil);
RMD.init ;
RMD.UpdateStr(AValue);
RMD.
Final(HashDigest);
s := '
' ;
for i:= 0
to ((RMD.HashSize
div 8)-1)
do begin // write out in hex
s:= s + IntToHex(HashDigest[i],2);
if ((i+1)
mod 2 = 0)
and (i <> ((RMD.HashSize
div 8)-1))
then s := s + '
-' ;
end ;
Result := s ;
//copy (s,1,4*5-1) ;
RMD.free ;
end;
initialization
finalization
end.