UTF8後MD5

  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;
相關文章
相關標籤/搜索