douyou9923 2015-03-14 15:00
浏览 15
已采纳

使用PHP错误的摘要值

I've got string:

$string = '<Predstavitev xmlns="http://www.sigen.si/PodpisaniDokument" Id="MyVisualisation2"><Podatki ca="SIGEN-CA" dsPodjetja="" dsUporabnika="12345678" emso="1212912500444" maticna="" serial="2462933412018"/></Predstavitev>';

and digest value of it should be

tmLGK3IVc1mC/r5ScUKXQ46wcCA=

but when I use this PHP code

echo base64_encode(hash('SHA1', $string, true));

the output is

yszGh284QybUiyVNLfQlkh358qQ=

In SOAP is reference for canonicalization method (http://www.w3.org/TR/2001/REC-xml-c14n-20010315) and digest method algorithm (http://www.w3.org/2000/09/xmldsig#sha1).

Thanks for help!

  • 写回答

2条回答 默认 最新

  • doukekui0914 2015-03-16 00:26
    关注

    If the digest value is wrong and the functions applied are correct, then the input value is wrong - and not the digest. The digest is correct in the sense that it's correct from the wrong input value.

    Therefore you need to apply the standards as you've named them (canonical form, digest) on the input you've got.

    If you're too lazy to do that your own, you can for example take an existing library for that which is able to parse the algorithms from the soap-response XML you've got:

    $string = '<Predstavitev xmlns="http://www.sigen.si/PodpisaniDokument" Id="MyVisualisation2"><Podatki ca="SIGEN-CA" dsPodjetja="" dsUporabnika="12345678" emso="1212912500444" maticna="" serial="2462933412018"/></Predstavitev>';
    
    $sig = new XMLDSig($soapResponse);
    
    var_dump($sig->getDigest($string)); // string(28) "tmLGK3IVc1mC/r5ScUKXQ46wcCA="
    

    The XMLDSig class is part of XMLUtil, also on packagist, just require "hakre/xmlutil": "dev-develop".

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)
  • ¥15 机器人轨迹规划相关问题
  • ¥15 word样式右侧翻页键消失