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条)

报告相同问题?

悬赏问题

  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳
  • ¥15 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥30 请帮我解决一下下面六个代码
  • ¥15 关于资源监视工具的e-care有知道的嘛
  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?