「Amazon CloudFront」:修訂間差異
跳至導覽
跳至搜尋
创建页面,内容为“== 範例 == === signing === <pre> <?php $key_pair_id = 'APKA...'; $pem_file = ''; $resource = 'http://test2-cdn.gslin.org/test.txt'; $expires = time() + 3600; $j…” |
|||
(未顯示同一使用者於中間所作的 4 次修訂) | |||
第1行: | 第1行: | ||
'''Amazon CloudFront'''是[[AWS]]所推出的[[CDN]]服務。 | |||
== 範例 == | == 範例 == | ||
=== signing === | === signing === | ||
< | <syntaxhighlight lang="php"> | ||
<?php | <?php | ||
$key_pair_id = 'APKA...'; | $key_pair_id = 'APKA...'; | ||
$pem_file = ''; | $pem_file = '/path/secret.pem'; | ||
$resource = 'http://test2-cdn.gslin.org/test.txt'; | $resource = 'http://test2-cdn.gslin.org/test.txt'; | ||
第42行: | 第44行: | ||
"Expires=${expires}&", | "Expires=${expires}&", | ||
"Signature=${signature}&", | "Signature=${signature}&", | ||
"Key-Pair-Id=${key_pair_id}\n";</ | "Key-Pair-Id=${key_pair_id}\n";</syntaxhighlight> | ||
== 外部連結 == | == 外部連結 == | ||
* {{Official|https://aws.amazon.com/cloudfront/}} | * {{Official|https://aws.amazon.com/cloudfront/}} {{en}} | ||
[[Category:服務]] | [[Category:服務]] |
於 2018年2月28日 (三) 02:16 的最新修訂
Amazon CloudFront是AWS所推出的CDN服務。
範例
signing
<?php
$key_pair_id = 'APKA...';
$pem_file = '/path/secret.pem';
$resource = 'http://test2-cdn.gslin.org/test.txt';
$expires = time() + 3600;
$json_str = json_encode(
array(
'Statement' => array(
array(
'Resource' => $resource,
'Condition' => array(
'DateLessThan' => array(
'AWS:EpochTime' => $expires
)
)
)
)
),
JSON_UNESCAPED_SLASHES
);
$buf = file_get_contents($pem_file);
$key = openssl_get_privatekey($buf);
openssl_sign($json_str, $signed_policy, $key, OPENSSL_ALGO_SHA1);
openssl_free_key($key);
$signature = str_replace(
array('+', '=', '/'),
array('-', '_', '~'),
base64_encode($signed_policy)
);
echo "${resource}?",
"Expires=${expires}&",
"Signature=${signature}&",
"Key-Pair-Id=${key_pair_id}\n";
外部連結
- 官方網站 (英文)