Text parsing using UTF-8 encoding and SHA256 hashing for Lazada signature

Hello! It’s my first time posting in a community like this… hopefully I’m doing this the right way! Please bear with me as my technical background is very weak.

[Goal]
From Make, I’m trying to call an API in Lazada.

For this, they require a “Signature” included in the request parameter, which uses some algorithm, UTF-8 encoding, and SHA256 hashing.
However, I can’t seem to get this right as I encounter an error that says “The request signature does not conform to platform standards.” I think I’m not able to follow the algorithm properly using Make, and would really appreciate your help.

[Lazada’s Signature algorithm]

So according to their documentation linked here, there are 5 steps to generating the signature.

Step 1: Sort all request parameters (including system and application parameters, but except the “sign” and parameters with byte array type) according to the parameter name in ASCII table. For example:

Before sort: foo=1, bar=2, foo_bar=3, foobar=4
After sort: bar=2, foo=1, foo_bar=3, foobar=4

Step2: Concatenate the sorted parameters and their values into a string. For example:

bar2foo1foo_bar3foobar4

Step3: Add the API name in front of the concatenated string. For example, adding the API name “/test/api”:

/test/apibar2foo1foo_bar3foobar4

Step4: Encode the concatenated string in UTF-8 format and make a digest by the signature algorithm (using HMAC_SHA256). For example:

hmac_sha256(/test/apibar2foo1foo_bar3foobar4)

Step5: 1. Convert the digest to hexadecimal format. For example:

hex(“helloworld”.getBytes(“utf-8”)) = “68656C6C6F776F726C64”

Steps 1 to 3 are straightforward. I’m trying to apply the resulting text into Steps4 and 5, which I think is the part I can’t figure out.

[Steps I tried]

I created the string and put it into the sha256 function like the below. (I’m also using the formatDate and parseDate function as a part of the signature because the signature requires a timestamp in the format of Unix Millisecond Timestamp. )


I’m not quite sure how to do Step 4, around encoding the string into UTF-8 format, and I’m guessing that may be my issue.

My error is the below.

Please help me on how to achieve this Signature!

1 Like

The sha256() function in Make has an encoding argument set to “hex” by default which will return the digest in hexadecimal format. There is no way to set the UTF-8 encoding ahead of time, but there may be an app that can set the UTF-8 on your string ahead of time before passing it to sha256().

/test/apibar2foo1foo_bar3foobar4{{formatDate(now; "X")}}

will append the UNIX milliseconds to the end of your API call

{{sha256("/test/apibar2foo1foo_bar3foobar4" + formatDate(now; "X") + ",hex")}}

will encode the SHA256 digest in hexadecimal format. Note you do not need the parseDate() function applied since now is already a date function that can be used in the formatDate() function as is.

3 Likes

Thank you for taking a look.

I think I need to find an app that can set the UTF-8 on the string. I’ve been searching for a solution but I can’t seem to find one…

Would really appreciate if you can point me towards the right direction!

I could not find one but honestly I don’t think that will change the text since you don’t have any characters that need UTF-8.

2 Likes

Thank you again - and apologies on my late reply as I’ve been still trying to work through this issue to no avail. I may be fundamentally getting how the API lazada works… I’ll try to study further.

There is a text encoding converter in the Tools app. It is called “Conver the encoding of a text” This this response for details:

2 Likes