Einzelnen Beitrag anzeigen

Peter666

Registriert seit: 11. Aug 2007
357 Beiträge
 
#1

Covid Zertifikatscheck

  Alt 12. Sep 2021, 12:22
Hi,

ich wollte eine Plattformunabhängige kleine App erstellen die Covid Zertifikate hinterlegt und auf Gültigkeit überprüft.

Im Prinzip ist das recht einfach. In dem QR Code ist ein Base45 kodierter String hinterlegt:

Delphi-Quellcode:
const
  _C2I: array[0..255] of byte = (
    255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
    255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
    36, 255, 255, 255, 37, 38, 255, 255, 255, 255, 39, 40, 255, 41, 42, 43,
    0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, 255, 255, 255, 255, 255,

    255, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
    23, 24, (* uppercase *)
    25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 35, 255, 255, 255, 255,
    255, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
    23, 24, (* lowercase *)
    25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 35, 255, 255, 255, 255,

    255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
    255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
    255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
    255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,

    255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
    255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
    255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
    255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255);


procedure base45_decode(const AInput, AOutput: TStream);
var
  ch, a, b: byte;
  x: word;
begin
  ch := 0;
  repeat
    AInput.Read(ch, 1);
    a := _C2I[ch];

    AInput.Read(ch, 1);
    b := _C2I[ch];

    if (a = 255) or (b = 255) then
      exit;

    x := a + 45 * b;

    if AInput.Position < AInput.Size then
    begin
      AInput.Read(ch, 1);
      a := _C2I[ch];

      if a = 255 then
        exit;
      x := x + (a * 45 * 45);

      ch := x shr 8;
      AOutput.Write(ch, 1);
    end;
    ch := x and $FF;
    AOutput.Write(ch, 1);
  until AInput.Position = AInput.Size;
end;
Der Text ist ein bzip stream und wenn dieser dekodiert ist, dann hat man ein CBOR/COSE Json. COSE hab ich ja auf Github schon gefunden bzw. eine eigene Version (basierend auf einer C Implementierung) geschrieben. CBOR gibt es aber irgendwie nicht für Delphi. Kennt sich jemand eventuell damit aus?

Peter
  Mit Zitat antworten Zitat