×

delphi 判断是否是Hash

ywlfff ywlfff 发表于2021-09-23 17:36:01 浏览904 评论0

抢沙发发表评论

function IsHash(Hash: String): boolean;

var i: integer;

begin

      Result := false;

      if Hash = '' then exit;

      if Length(Hash) = 32 then   // possible base32 encoded hash

                      try

                        Hash:=StrToHex(Base32Decode(UpperCase(Hash)));

                      except

                        exit;

                      end;

    if Length(Hash) <> 40 then exit;

    Result := true;

    for i := 1 to 40 do if not (Hash[i] in ['a' .. 'f', 'A'..'F', '0'..'9']) then Result := false;

end;