我正在开发一个需要通过Webservices与另一个系统通信的ColdFusion站点.对于其他系统,我在PHP中有一个关于如何生成基于SHA512的哈希的示例,我试图在ColdFusion中复制相同的函数,但它只是不起作用.
该示例包括字符串和键,以及预期的编码结果.但是我没有使用ColdFusion获得相同的编码字符串.也许我在某个地方错过了ToBase64或其他转换功能,但我没有想法,真的需要帮助来实现这个功能.
任何帮助都会非常感激.
//signature to acquire a session
$apiId = '1lie8ficql9h5';
$apiSecret = 'j6hriaKY2iZi+Y2uo9JJldmO1Bq79XB8d1v2uHzAK0Zvy972mIs8ThsJSQeDlZJz+HzmLD6Q1MUZb5X1Zf9MzQ==';
//build the string to sign
//note the order of the entries is important.
//The http headers must be in alphabetical order by key name
$httpMethod = 'POST';
$apiKey = 'x-csod-api-key:'.$apiId;
$httpUrl = '/services/api/sts/session';
date_default_timezone_set('UTC');
$date = 'x-csod-date:'.date('Y-m-d').'T'.date('H:i:s').'.000';
$stringToSign = $httpMethod."\n".$apiKey."\n".$date."\n".$httpUrl;
/* produces the following string:
* POST\nx-csod-api-key:1lie8ficql9h5\nx-csod-date:2015-09-08T11:27:32.000\n/services/api/sts/session
*/
//Generate the signature
$secretKey = base64_decode($apiSecret);
$signature = base64_encode(hash_hmac('sha512', $stringToSign, $secretKey, true));
/*
* signature produced:
* …Run Code Online (Sandbox Code Playgroud)