Einzelnen Beitrag anzeigen

mytbo

Registriert seit: 8. Jan 2007
472 Beiträge
 
#26

AW: TGUID - einzigartige ID auf andere Computer Systeme ?

  Alt 27. Okt 2023, 23:48
Für alle, die es schon vermisst haben, mORMot hat dieses Angebot:
Zitat:
TSynUniqueIdentifierGenerator: thread-safe 64-bit integer unique identifier computation
- contain generation time
- they are increasing over time (so are much easier to store/shard/balance than UUID/GUID)
- each identifier would contain a 16-bit process identifier, which is supplied by the application
- identifiers may be obfuscated as hexadecimal text, using both encryption and digital signature
Hier etwas Quelltext:
Delphi-Quellcode:
uses
  mormot.core.base,
  mormot.core.unicode,
  mormot.crypt.secure;

var
  guid: Int64;
  guidStr: String;
  guidGen: TSynUniqueIdentifierGenerator;
begin
  guidGen := TSynUniqueIdentifierGenerator.Create({Identifier:}12345, {SharedObfuscationKey:}'TopSecret', 10); // create once in application
  try
    guid := guidGen.ComputeNew;
    ShowMessage(Format('Guid: %s', [guid.ToString]));

    guidStr := Utf8ToString(guidGen.ToObfuscated(guid));
    ShowMessage(Format('Guid obfuscated: %s', [guidStr]));

    var fromObfuscatedGuid: TSynUniqueIdentifier; // Int64
    if guidGen.FromObfuscated(StringToUtf8(guidStr), fromObfuscatedGuid) then
      ShowMessage(Format('Guid: %d, From obfuscated: %d', [guid, Int64(fromObfuscatedGuid)]));

    var guidBits: TSynUniqueIdentifierBits;
    guidBits.From(guid);
    ShowMessage(Format('DateTime created: %s', [DateTimeToStr(guidBits.CreateDateTime)]));

    ShowMessage(Format('JSON: %s', [Utf8ToString(guidBits.AsVariant._JSON)]));
  finally
    guidGen.Free;
  end;
Im Beispiel ist der Identifikator "12345". Es stehen 16-Bit zur Verfügung. Eine Möglichkeit wäre, jedem Kunden/Installation eine eigene zuzuweisen.

Die Ausgabe für das Beispiel ist:
Code:
Guid: 3647375681599078401
Guid obfuscated: 7dc1647a8d032aaeebe65dff209d32ff
Guid: 3647375681599078401, From obfuscated: 3647375681599078401
DateTime created: 27.10.2023 21:20:55
JSON: {"Created":"2023-10-27T21:20:55","Identifier":12345,"Counter":1,"Value":3647375681599078401,"Hex":"329E14DB981C8001"}
Bis bald...
Thomas
  Mit Zitat antworten Zitat