Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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


Please help me out here...

Thanks.







Posted
Updated 25-Apr-15 8:36am
v3

1 solution

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.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900