1

I am trying to generate the HMAC SHA1 Hash to use the Railway PNR API.

I am using PHP Framework Codeigniter. I used the helper given here.

Then I tried to generate the hash and compare it with the Hash Generator given in the Rail PNR API site.

But both the hash i.e. the one I generated and the one I am getting from the Rail PNR API site are not the same.

Then I tried to use online tools to generate the hash value for the same. But still the hash that is generated is not same as that is coming from the API site.

My three data are in the following way:

  • PNR: 1234567890
  • Format: json
  • Public Api Key: <My Public Api Key>

So the data that has to be hashed is: 1234567890json<My Public Api Key> using the <My Private Api Key>

I don't know that if the method to generate hash is wrong or if I am doing it wrong. I pretty much followed every step that is stated there correctly.

I am okay if the solution is available in javascript, but PHP is more preferred.

EDIT:

I even read the following but they couldn't help:

-- Trying to digitally sign via HMAC-SHA1 with PHP

-- OpenSSL HMAC-SHA1 digest does not match Crypto's

Please help me out here...

Thanks.

Community
  • 1
  • 1
Benison Sam
  • 2,755
  • 7
  • 30
  • 40
  • 1
    Their generator page says "Pass this string and your private key to the HMAC SHA1 generator function and get the HMAC signature for your request." Are you sure that the HMAC algorithm they have in mind is the same as the one on the code ignitor forum? The algo should be pretty standard, but it's worth [asking them](http://railpnrapi.com/hauth/contact) in my opinion. – Patrick M Apr 23 '15 at 18:03
  • Thanks. Patrick for the reply. Yes, now I think its better to ask them rather than to try and see with everything I've got. – Benison Sam Apr 24 '15 at 07:28

1 Answers1

0

The values that are to be passed in the API is supposed to be in the alphabetical order. Like in my case above, if we arrange the keys in alphabetical order the keys will be: format, pbapisign (i.e. the public key) and pnr.

So the string to be hashed will be 'json'.'<My Public API Key>'.'1234567890'.

Now to generate the hash, basically you can use any PHP function. I use the hash_hmac() function to generate the hash.

Now its working for me. Hope this helps anyone who's working with the Rail PNR API.

Thanks.

Benison Sam
  • 2,755
  • 7
  • 30
  • 40