0

I have been following the documentation in the Viber REST API to create a signature with HMAC using SHA256 Callack Section. The key is authentication token and the value is a json. I tried to create the signature using hash_hmac in PHP language but to no avail. I keep getting different results. I tried to beautify and adjust the structure of json but to no avail.

What I've Done:

public function index(Request $request)
{
    $value = $request->getContent();
    $value = hash_hmac("sha256", $value, '4453b6ac12345678-e02c5f12174805f9-daec9cbb5448c51f');

    return $value;
}

Returned Result: 99b1988ed94ea0e336f5d670c5c71c793bd72f0bb65af2ccbe1f943cae23488c

Key:

4453b6ac12345678-e02c5f12174805f9-daec9cbb5448c51f

Json:

{  
   "event":"delivered",
   "timestamp":1457764197627,
   "message_token":491266184665523145,
   "user_id":"01234567890A="
}

Correct Result Should Be:

9d3941b33d45c165400d84dba9328ee0b687a5a18b347617091be0a56d
MiniDr
  • 191
  • 1
  • 11
  • Are you actually getting that exact same JSON the docs gave as an example? Or are you testing this with actual incoming webhook data? – CBroe Aug 25 '22 at 06:23
  • the signature will vary greatly even if a single space/newline is out of place. Have you tried this code to see if it works anyway if you send the correct body with matching signature? – apokryfos Aug 25 '22 at 06:31
  • @CBroe Currently, I am trying to get the Output result provided in that documentation with same Key and JSON before I try it with any other callback data. However, to no avail. I did try adjusting the json like by moving/removing the spaces - putting 1, 2, 3 lines before each field in json. – MiniDr Aug 26 '22 at 02:08
  • @apokryfos Yeah that's what I did. I keep rearranging the json value but can't seem to get that exact structured Json. I did just copy and paste the Json and tested it in Postman - was not able to get the correct output/result. – MiniDr Aug 26 '22 at 02:10
  • That's not what I was saying though. I'm suggesting you send the request to the API with whatever signature you are getting anyway and check to see if it works. It's possible their output in the docs is an example value and not the actual matching value for that input – apokryfos Aug 26 '22 at 04:17

0 Answers0