【发布时间】:2015-09-22 17:31:18
【问题描述】:
我正在使用 SDK 版本 2.8.21 来使用 KMS。
我有一个 config.php 文件,其中包含
<?php
// File saved as /path/to/custom/config.php
require 'vendor/autoload.php';
use Doctrine\Common\Cache\FilesystemCache;
use Guzzle\Cache\DoctrineCacheAdapter;
// Create a cache adapter that stores data on the filesystem
$cacheAdapter = new DoctrineCacheAdapter(new FilesystemCache('/tmp/cache'));
return array(
'includes' => array('_aws'),
'services' => array(
'default_settings' => array(
'params' => array(
'credentials.cache' => $cacheAdapter
)
)
)
);
下面是我用来做测试加密的test.php文件。
<?php
require 'vendor/autoload.php';
use Aws\Common\Aws;
// Create the AWS service builder, providing the path to the config file
try {
$keyId = '<KMSKEYALIAS>';
$aws = Aws::factory('config.php');
$client = $aws->get('kms');
$result = $client->encrypt(array(
'KeyId' => $keyId,
'Plaintext' => 'This is the song that never ends...'
));
print_r($result);
}
catch (\Exception $e)
{
echo $e->getMessage()."\n\n";
}
当我执行 php test.php 时,我得到“使用 AWS Key Management Service 时需要一个区域”。
认为这可能是我们使用 CLI 工具测试的服务器 IAM 问题。
aws kms encrypt --key-id <KMSKEYALIAS> --plaintext "1\!2@3#4$5%6^7&8*9(0)-_=+" --query CiphertextBlob --output text | base64 --decode > /tmp/encrypt.txt
并且 /tmp/encrypted.txt 包含加密数据。
我很茫然,真的可以使用一些帮助来确定这是 aws 中的错误还是我做错了什么。
我目前无法升级到 v3.x,因为我们使用的是 php 5.4,并且现在无法升级到 5.5。
【问题讨论】:
-
您需要在您的
config.php文件中指定一个region。这是有效区域列表docs.aws.amazon.com/general/latest/gr/rande.html#kms_region