我一直在使用我的航空公司供应商提供的公式创建哈希密码。我在这个网站上搜索过,我从C#下面的链接中得到了解决方案,但我希望用PHP。 Working algorithm for PasswordDigest in WS-Security
我在php中尝试了这样但我得到的密码摘要是错误的
function getTimestamp()
{
$microtime = floatval(substr((string)microtime(), 1, 8));
$rounded = round($microtime, 3);
return gmdate("Y-m-d\TH:i:s") . substr((string)$rounded, 1, strlen($rounded))."Z";
}
$nounce = base64_encode(mt_rand(10000000, 99999999));
$timestamp = getTimestamp();
$password = "AMADEUS"; //clear password
$final_hashed_password = base64_encode(sha1($nounce.$timestamp.sha1($password)));
我的价值就是这样产生的
Nonce: ODczNzczNzE=
Timestamp: 2014-09-21T06:36:31.328Z
password: "TEST"
password digest I got: NjQxOThmZjViNmIwOGM0NGNiNDE1YTExNWQ3MDc2OGNlYjBjZDY2MA==
但密码摘要应该像这样生成
Right password digest: zGXsP85SuUngY7FjtnQizeO6yUk=
我知道创建摘要的算法是:
Password_Digest = Base64 ( SHA-1 ( nonce + created + SHA-1 ( password ) ) )
请帮我在php中生成正确的哈希密码,也请看上面有c#解决方案的链接
答案 0 :(得分:2)
得到了解决方案!...我们必须对nonce进行解码,然后在其上应用公式,在xml中我们必须发送编码的nonce
答案 1 :(得分:0)
正如你所提到的 - 问题出在Nonce。
如果我建议,最好使用nonce一个字节流(random_bytes
),而不是mt_rand(10000000, 99999999)
而不编码它。然后,只有在将它包含在Nonce SOAP / XML节点中时才对其进行编码。