unit uHandlingCrypt;
interface
function EncryptString(Str, PassPhrase:
String):
String;
function DecryptString(Str, PassPhrase:
String):
String;
implementation
uses
uTPLb_CryptographicLibrary,
uTPLb_Codec,
System.SysUtils;
function EncryptString(Str, Passphrase:
String):
String;
var
CryptLib: TCryptographicLibrary;
Codec: TCodec;
begin
//init
result := EmptyStr;
CryptLib := TCryptographicLibrary.Create(
nil);
try
Codec := TCodec.Create(
nil);
try
Codec.CryptoLibrary := CryptLib;
Codec.StreamCipherId := '
native.StreamToBlock';
Codec.BlockCipherId := '
native.AES-256';
Codec.ChainModeId := '
native.ECB';
Codec.Password := PassPhrase;
Codec.EncryptString(Str, result, TEncoding.UTF8);
//<--hier wird der Fehler in der Bereichsprüfung ausgelöst
finally
Codec.Free;
end;
{try..finally}
finally
CryptLib.Free;
end;
{try..finally}
end;
function DecryptString(Str, PassPhrase:
String):
String;
var
CryptLib: TCryptographicLibrary;
Codec: TCodec;
begin
//init
result := EmptyStr;
CryptLib := TCryptographicLibrary.Create(
nil);
try
Codec := TCodec.Create(
nil);
try
Codec.CryptoLibrary := CryptLib;
Codec.StreamCipherId := '
native.StreamToBlock';
Codec.BlockCipherId := '
native.AES-256';
Codec.ChainModeId := '
native.ECB';
Codec.Password := PassPhrase;
Codec.DecryptString(result, Str, TEncoding.UTF8);
//<--hier wird der Fehler in der Bereichsprüfung ausgelöst
finally
Codec.Free;
end;
{try..finally}
finally
CryptLib.Free;
end;
{try..finally}
end;
end.