dousong1926 2012-07-06 12:49
浏览 25
已采纳

为banklink创建签名的问题

I'm stuck finilizing a banklink, I get response, that my signature is wrong.

This is the signature part manual that the bank sent

Digital signature MAC is XML data hash value, encrypted with senders private key.
For hash value calculations SHA-1 algorithm is used, but for signature calculation RSA algorithm is used. Digital signature transforms to textual format using BASE64 encoding and is placed to MAC field.

And what I have build up:

// the key is loaded succesfull
private function setPrivateKey ( $key_name ) {
  $fp = fopen( $this -> getKeyLocation() . '/' . $key_name, "r" );
  $priv_key = fread( $fp, 8192 );
  fclose( $fp );
  $this -> private_key = openssl_get_privatekey( $priv_key );
}

// signature is created, but not the way bank expects it
private function setSignature () {
  // also tried sha1( $data, true );
  // signature contains no special chars ( meaning no UTF8 specific coding )
  $pre_mac = sha1( $this -> getXMLData() );
  openssl_sign( $pre_mac, $signature, $this -> getPrivateKey() );
  $this -> signature = $signature;
}

// can't be a problem here
private function setMac () {
  $this -> mac = base64_encode( $this -> getSignature() );
}

// this is set correctly
private function setXMLData () {
    $bank_xml = '<?xml version="1.0" ?>
    <bl>
    <snd>PHP_COMPANY</snd>
    <query>NEW</query>
    <type>PHP_TYPE</type>
    <data>
        <client_id>A71045</client_id>
        <amount>PHP_AMOUNT</amount>
        <ccy_name>PHP_CURR</ccy_name>
        <ccy_code>1</ccy_code>
        <bnf_name>PHP_COMPANY</bnf_name>
        <bnf_account>PHP_ACCOUNT</bnf_account>
        <bnf_id>PHP_CID</bnf_id>
        <residence_id>LV</residence_id>
        <residence_name>LV-LATVIA</residence_name>
        <details>PHP_DETAILS</details>
    </data>
    <date>PHP_DATE</date>
    <time>PHP_TIME</time>
    <reply>
        <session_id>PHP_SESSION</session_id>
    </reply>
    <reply_url>PHP_REPLY</reply_url>
    </bl>';

    $this -> bank_xml = $bank_xml;
}

It seems to me that I'm not encrypting it right. Any suggestions what might be wrong? I believe I have made every step what the bank requires.

I already sent this to the bank, but they respond w/in a week or so.

PS: get functions are all set that return the set variable, I just didn't think it's necessary to post them.

  • 写回答

1条回答 默认 最新

  • dougaojue8185 2012-07-06 13:46
    关注

    Ok, fixed the problem. It seems that the bank manual is not correct ( still waiting for the answer from bank though ).

    Replaced sha1 with md5 and all became valid.

    $pre_mac = md5( $this -> getXMLData() );
    

    Thanx raina77ow, you pointed me to the right direction with your coment:

    did you try omitting that intermediate hashing altogether?

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

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看