为 Amadeus SOAP 创建密码摘要时出现问题 API
Issue creating password digest for Amadeus SOAP API
我按照文档中的说明进行操作,并尝试在 Node 中执行相同的公式,但是,当我收到 11|Session|
响应时,我无法正确地向服务器进行身份验证。我认为该错误是对错误设置随机数 and/or 密码摘要的响应。
公式:Base64(SHA1($NONCE + $TIMESTAMP + SHA1($CLEARPASSWORD)))
变量:$CLEARPASSWORD=AMADEUS
、$TIMESTAMP=2015-09-30T14:12:15Z
、$NONCE=c2VjcmV0bm9uY2UxMDExMQ==
。
预期哈希值:+LzcaRc+ndGAcZIXmq/N7xGes+k=
我试过的代码是:
const crypto = require('crypto')
const hashedPassword = crypto.createHash('sha1').update(CLEARPASSWORD).digest() // Returns a buffer
crypto.createHash('sha1').update(NONCE + TIMESTAMP + hashedPassword).digest('base64') // Returns a Base64 String
不过,这个returnsDDcZEaS5AtoVaZhsARy9MqV+Y34=
。如果我将 nonce 更改为其纯字符串 secretnonce10111
,那么我会得到 gHOoqyDb9YJBrk30iabSO8nKxio=
,但仍然不正确。
我不确定可能是什么问题。
我终于知道哪里出了问题。问题是我试图将一个字符串与一个缓冲区连接起来,而我本应该从一开始就将所有内容都设为缓冲区。
所以,而不是
const hashedPassword = crypto.createHash('sha1').update(CLEARPASSWORD).digest()
crypto.createHash('sha1').update(NONCE + TIMESTAMP + hashedPassword).digest('base64')
应该是
const buffer = Buffer.concat([Buffer.from(NONCE), Buffer.from(TIMESTAMP), nodeCrypto.createHash('sha1').update(CLEARPASSWORD).digest()])
const hashedPassword = nodeCrypto.createHash("sha1").update(buffer).digest("base64")
you can use this php code to generate Digest Password
<?php
date_default_timezone_set('UTC');
$t = microtime(true);
$micro = sprintf("%03d",($t - floor($t)) * 1000);
$date = new DateTime( date('Y-m-d H:i:s.'.$micro) );
echo $timestamp = $date->format("Y-m-d\TH:i:s").$micro . 'Z';
$nonce = mt_rand(10000000, 99999999);
echo $nounce = base64_encode($nonce);//we have to decode the nonce and then apply the formula on it and in xml we have to send the encoded nonce
$password = "AMADEUS"; //clear password
echo $passSHA = base64_encode(sha1($nonce . $timestamp . sha1($password, true), true));
?>
我按照文档中的说明进行操作,并尝试在 Node 中执行相同的公式,但是,当我收到 11|Session|
响应时,我无法正确地向服务器进行身份验证。我认为该错误是对错误设置随机数 and/or 密码摘要的响应。
公式:Base64(SHA1($NONCE + $TIMESTAMP + SHA1($CLEARPASSWORD)))
变量:$CLEARPASSWORD=AMADEUS
、$TIMESTAMP=2015-09-30T14:12:15Z
、$NONCE=c2VjcmV0bm9uY2UxMDExMQ==
。
预期哈希值:+LzcaRc+ndGAcZIXmq/N7xGes+k=
我试过的代码是:
const crypto = require('crypto')
const hashedPassword = crypto.createHash('sha1').update(CLEARPASSWORD).digest() // Returns a buffer
crypto.createHash('sha1').update(NONCE + TIMESTAMP + hashedPassword).digest('base64') // Returns a Base64 String
不过,这个returnsDDcZEaS5AtoVaZhsARy9MqV+Y34=
。如果我将 nonce 更改为其纯字符串 secretnonce10111
,那么我会得到 gHOoqyDb9YJBrk30iabSO8nKxio=
,但仍然不正确。
我不确定可能是什么问题。
我终于知道哪里出了问题。问题是我试图将一个字符串与一个缓冲区连接起来,而我本应该从一开始就将所有内容都设为缓冲区。
所以,而不是
const hashedPassword = crypto.createHash('sha1').update(CLEARPASSWORD).digest()
crypto.createHash('sha1').update(NONCE + TIMESTAMP + hashedPassword).digest('base64')
应该是
const buffer = Buffer.concat([Buffer.from(NONCE), Buffer.from(TIMESTAMP), nodeCrypto.createHash('sha1').update(CLEARPASSWORD).digest()])
const hashedPassword = nodeCrypto.createHash("sha1").update(buffer).digest("base64")
you can use this php code to generate Digest Password
<?php
date_default_timezone_set('UTC');
$t = microtime(true);
$micro = sprintf("%03d",($t - floor($t)) * 1000);
$date = new DateTime( date('Y-m-d H:i:s.'.$micro) );
echo $timestamp = $date->format("Y-m-d\TH:i:s").$micro . 'Z';
$nonce = mt_rand(10000000, 99999999);
echo $nounce = base64_encode($nonce);//we have to decode the nonce and then apply the formula on it and in xml we have to send the encoded nonce
$password = "AMADEUS"; //clear password
echo $passSHA = base64_encode(sha1($nonce . $timestamp . sha1($password, true), true));
?>