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.

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

报告相同问题?

悬赏问题

  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型