I am very new to WAS, I want to implement a client side encryption for the DynamoDB in php. I did not find any document that can show me how to it. I tried this tutorial https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/s3-encryption-client.html, but this is for S3 not Dynamodb.
Then I tried this tutorial https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/kms-example-encrypt.html.
It shows me how to use the KmsClient to encrypt data in client side.
I change the version and region for the KmsClient to the corresponding values, the version I get from the Encryption keys page, under key policy
"Version": "2012-10-17",
The region I get
Region ap-southeast-2
I have the credential file like below in the .aws/ floder
[default]
aws_access_key_id = ***************
aws_secret_access_key = **************
I also changed the key id to the one I just created.
But I keep get this error
#0 /Users/ditto/Sites/site/php/vendor/aws/aws-sdk-
php/src/ClientResolver.php(427):
Aws\Api\ApiProvider::resolve(Object(Aws\Api\ApiProvider), 'api',
'kms', '2012-10-17')
#1 /Users/ditto/Sites/site/php/vendor/aws/aws-sdk-
php/src/ClientResolver.php(288):
Aws\ClientResolver::_apply_api_provider(Object(Aws\Api\ApiProvider),
Array, Object(Aws\HandlerList))
#2 /Users/ditto/Sites/site/php/vendor/aws/aws-sdk-
php/src/AwsClient.php(158): Aws\ClientResolver->resolve(Array,
Object(Aws\HandlerList))
#3 /Users/ditto/Sites/site/php/signUpCopy.php(22):
Aws\AwsClient->__construct(Array)
#4 {main}
thrown in /Users/ditto/Sites/site/php/vendor/aws/aws-sdk-php/src/Api/ApiProvider.php on line 85
This is my code:
include ('config.php');
require ('vendor/autoload.php');
use Aws\Kms\KmsClient;
use Aws\Exception\AwsException;
$message = pack('c*',1,2,3,4,5,6,7,8,9,0);
$KmsClient = new Aws\Kms\KmsClient([
'profile' => 'default',
'version' => '2012-10-17',
'region' => 'ap-southeast-2'
]);
$keyId = '***************************';
$message = pack('c*', 1, 2, 3, 4, 5, 6, 7, 8, 9, 0);
try {
$result = $KmsClient->encrypt([
'KeyId' => $keyId,
'Plaintext' => $message,
]);
var_dump($result);
} catch (AwsException $e) {
// output error message if fails
echo $e->getMessage();
echo "
";
}
I do not know where I did it wrong.