duannuci4008 2015-04-18 17:13
浏览 58
已采纳

在PHP中为Rail PNR API生成HMAC SHA1

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.

  • 写回答

1条回答 默认 最新

  • douyouqian8550 2015-04-26 05:54
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复