Skip to content

Instantly share code, notes, and snippets.

@iogi
Created March 21, 2014 10:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iogi/9683701 to your computer and use it in GitHub Desktop.
Save iogi/9683701 to your computer and use it in GitHub Desktop.
<?php
// Signature Version 4 Key Derivation Samples in PHP5
// http://docs.aws.amazon.com/general/latest/gr/signature-v4-examples.html
function hash_sha256_raw($msg, $key)
{
return hash_hmac("sha256", $msg, $key, true);
}
function getSignature($key, $dateStamp, $regionName, $serviceName)
{
$kDate = hash_sha256_raw($dateStamp, "AWS4$key");
$kRegion = hash_sha256_raw($regionName, $kDate);
$kService = hash_sha256_raw($serviceName, $kRegion);
$kSigning = hash_sha256_raw("aws4_request", $kService);
return $kSigning;
}
$key = 'wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY';
$dateStamp = '20120215';
$regionName = 'us-east-1';
$serviceName = 'iam';
$signature = getSignature($key, $dateStamp, $regionName, $serviceName);
echo bin2hex($signature);
@iogi
Copy link
Author

iogi commented Mar 21, 2014

最近のPHPコーディングスタンダード事情に疎く関数名とか変数名はcamel caseなのかどうか

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment