guid-tool-web icon indicating copy to clipboard operation
guid-tool-web copied to clipboard

Converting b64 to HEX outputs unexpected GUID

Open GrayedFox opened this issue 9 years ago • 1 comments

Hey there,

Really like your tool - trying to incorporate in some tests I'm doing with Postman.

Thing is, if I throw a GUID at the API, it returns me a B64 value that is decoded into something different.

For example:

curl -d 'guid=2b88f261-bf4a-4972-90ad-845dac554a06' http://guid-convert.appspot.com/query

Returns

{
  "status": "success",
  "int": "57867872278969410912862791724044732934",
  "hex": "2b88f261-bf4a-4972-90ad-845dac554a06",
  "b64": "YfKIK0q/ckmQrYRdrFVKBg=="
}

But heading over to http://tomeko.net/online_tools/base64.php?lang=en B64 to Hex decoder outputs something different!

It gives:

61f2882b-4abf-7249-90ad-845dac554a06

As the output result. Notice the pairs of digits are mixed up? I.e. 7249 instead of 4972.

Thanks for the tool

GrayedFox avatar Feb 16 '16 17:02 GrayedFox

I wrote a work around for this, if anyone is interested. Probably a little bloated, but works for me. In this case, I am passing the response from the API to a variable called jsonData and working from there.

var jsonData = JSON.parse(responseBody);
var hexString = jsonData.hex.replace(/-/g, "");
var hexArray = hexString.match(/.{2}/g);
var cleanedArray = [];
var cleanedString = "";

function swapElements(array, pos1, pos2) {
    var temp = array[pos1];
    array[pos1] = array[pos2];
    array[pos2] = temp;
    return array;
}

cleanedArray = swapElements(hexArray, 0, 3);
cleanedArray = swapElements(hexArray, 1, 2);
cleanedArray = swapElements(hexArray, 4, 5);
cleanedArray = swapElements(hexArray, 6, 7);

cleanedString = cleanedArray.toString();
cleanedString = cleanedString.replace(/,/g, "");

console.log(cleanedArray);
console.log(cleanedString);

GrayedFox avatar Feb 17 '16 17:02 GrayedFox