I am wondering if anyone has successfully generated an EC2 v2 signature for their API using php. All examples/libraries I can find online are for v1 of the signature and that has been deprecated due to insecurities. An existing library that implements the signature generation would be appreciated too.
2330 次
4 回答
1
于 2009-11-25T00:34:04.927 回答
0
Here's a PHP Library that supports V2. I haven't tried it though.
于 2009-04-08T00:04:56.030 回答
0
使用常量 AWSSECRET 来散列签名,而不是 $AWSKEY(未引用的变量)。
于 2012-05-13T07:28:53.407 回答
0
这是我编写并一直在使用的一些代码:
define("AWSKEY", "Your AWS Key");
define("AWSSECRET", "Your AWS Secret");
public function get($parameters, $host) {
// Build out the variables
$domain = "https://$host/";
$parameters['AWSAccessKeyId'] = AWSKEY;
$parameters['Timestamp'] = date('c');
$parameters['Version'] = '2007-11-07';
$parameters['SignatureMethod'] = 'HmacSHA256';
$parameters['SignatureVersion'] = 2;
// Write the signature
$signature = "GET\n";
$signature .= "$host\n";
$signature .= "/\n";
$sigparams = $parameters;
ksort($sigparams);
$first = true;
foreach($sigparams as $key=>$param) {
$signature .= (!$first ? '&' : '') . rawurlencode($key) . '=' . rawurlencode($param);
$first = false;
}
$signature = hash_hmac('sha256', $signature, $AWSKEY, true);
$signature = base64_encode($signature);
$parameters['Signature'] = $signature;
$url = $domain . '?';
$first = true;
foreach($parameters as $key=>$param) {
$url .= (!$first ? '&' : '') . rawurlencode($key) . '=' . rawurlencode($param);
$first = false;
}
$ch = curl_init(trim($url));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
return $output;
}
下面是你如何使用它:
$params = array(
'Action' => 'ListDomains'
);
$db->get($params, 'sdb.amazonaws.com');
ListDomains
这将在 SimpleDB 上执行查询。该函数本身将返回 Amazon 的输出。对于更复杂的命令(即:PUT、POST 等),不需要进行任何重大修改。
于 2009-11-25T00:25:09.743 回答