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

报告相同问题?

悬赏问题

  • ¥23 (标签-bug|关键词-密码错误加密)
  • ¥66 比特币地址如何生成taproot地址
  • ¥20 数学建模数学建模需要
  • ¥15 关于#lua#的问题,请各位专家解答!
  • ¥15 什么设备可以研究OFDM的60GHz毫米波信道模型
  • ¥15 不知道是该怎么引用多个函数片段
  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决