function ToUTF8Encode(str: string): string; //将字符串转UTF8编码
var
b: Byte;
begin
for b in BytesOf(UTF8Encode(str)) do
Result := Format('%s%%%.2x', [Result, b]);
end;
function Encode(const KeyContent, content : string) : string;//加密(密钥, 待加密串)
var
md5key : string;
MyMD5: TIdHashMessageDigest5;
begin
md5key := ToUTF8Encode(KeyContent);
MyMD5 := TIdHashMessageDigest5.Create;
try
Result := ToUTF8Encode(Base64EncodeString(MyMD5.HashStringAsHex(content + md5key, enUTF8)));
finally
MyMD5.free;
end;
end;
const
Key = 'abc';
var
Code : string;
begin
Code := Encode(Key, '123abc');
ShowMessage(Code);
end;