unit uSimpleEncryption;
interface
uses SynCommons, SynCrypto;
function encrypt(aString:String):String;
function decrypt(aString:String):String;
implementation
const
my_key = 'derVerschLuessElLungsKeyimmerWiederNett';
function encrypt(aString:String):String;
var
key : TSHA256Digest;
aes : TAESCFB;
s:RawByteString;
begin
SynCommons.HexToBin(Pointer(SHA256(my_key)), @key, 32);
aes := TAESCFB.Create(key, 256);
try
s := StringToUTF8(aString);
s := BinToBase64(aes.EncryptPKCS7(s, True));
Result := UTF8ToString(s);
finally
aes.Free;
end;
end;
function decrypt(aString:String):String;
var
key : TSHA256Digest;
aes : TAESCFB;
s:RawByteString;
begin
SynCommons.HexToBin(Pointer(SHA256(my_key)), @key, 32);
aes := TAESCFB.Create(key, 256);
try
s := StringToUTF8(aString);
s := aes.DecryptPKCS7(Base64ToBin(s), True);
Result := UTF8ToString(s);
finally
aes.Free;
end;
end;
end.