Created
March 21, 2014 10:52
-
-
Save iogi/9683701 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
最近のPHPコーディングスタンダード事情に疎く関数名とか変数名はcamel caseなのかどうか