Author Topic: Decoding UUID v4  (Read 102 times)

dev guy

  • Newbie
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Decoding UUID v4
« on: January 17, 2018, 04:20:57 PM »
Does anyone know of a Chilkat tool that can decode an encoded UUID? I am trying to parse a Sendgrid webhook JSON document. The field that I am stuck on is sg_event_id. The data in the field is a Base64 string and I cannot convert back to its original form. A UUID v4 should look like this: cbaf5c4a-9623-46f0-8e0b-5f88f1ce5934.

The documentation form SendGrid says this:
sg_event_id comes in two different lengths. One that is 22 characaters long and a second that is 48 characters long.sg_event_idis actually a UUID. A UUID` is 128 bit number that is usually presented as text.

48 character sg_event_id is a UUIDv4 encoded and Base64 decoded string. 22 character sg_event_id is a Base64url encoded string.

Code: [Select]
{"email":"","timestamp":1516218585,"smtp-id":"\u003c14c5d75ce93.dfd.64b469@ismtpd-555\u003e","event":"deferred","category":"cat facts","sg_event_id":"nBOHXdXAXAH7mjuhx9xLVw==","sg_message_id":"14c5d75ce93.dfd.64b469.filter0001.16648.5515E0B88.0","response":"400 try again later","attempt":"5"}
ASP Code: oJ is JsonObject, oBin is BinData object
Code: [Select]
val = oJ.StringOf("sg_event_id") 'nBOHXdXAXAH7mjuhx9xLVw==
oBin.LoadEncoded val, "Base64"
Response.Write oBin.GetString("utf-8") & "<br/>"

This returns
Code: [Select]