我一直在使用 AWS SDK V3 for PHP 将对象放入 S3,并使用客户提供的密钥进行服务器端加密。该文档非常粗略(或者至少我还没有找到它)。
为了使用 S3client 上传对象,我使用 putobject
$params['SSECustomerAlgorithm'] = 'AES256';
$params['SSECustomerKey'] = $this->encryptioncustkey;
$params['SSECustomerKeyMD5'] = $this->encryptioncustkeymd5;
$this->encryptioncustkey 是一个普通的客户密钥(不是 base64_encoded,因为 SDK 似乎正在这样做)和 this->encryptioncustkeymd5 = md5($this->encryptioncustkey,true);
put 对象工作正常。但是,问题在于生成 createSignedURL。
$cmd = $client->getCommand('GetObject', array(
'Bucket' => $bucket,
'Key' => $storedPath,
'ResponseContentDisposition' => 'attachment;charset=utf-8;filename="'.utf8_encode($fileName).'"',
'ResponseContentType' => $ctype,
'SSECustomerAlgorithm' => 'AES256',
'SSECustomerKey' => $this->encryptioncustkey,
'SSECustomerKeyMD5' => $this->encryptioncustkey64md5
));
但我收到一个奇怪的响应,表明它缺少“x-amz-server-side-encryption”(ServerSideEncryption),根据文档,SSE-C 不需要它。即使我将它设置为 ServerSideEncryption='AES256' 它也没有效果。
<Error>
<Code>InvalidArgument</Code>
<Message>
Requests specifying Server Side Encryption with Customer provided keys must provide an appropriate secret key.
</Message>
<ArgumentName>x-amz-server-side-encryption</ArgumentName>
<ArgumentValue>null</ArgumentValue>
<RequestId>A3368F6CE5DD310D</RequestId>
<HostId>
nHavXXz/gFOoJT0tnh+wgFTbTgGdpggRkyb0sDh07H7SomcX7HrcKU1dDzgZimrQwyaVQEqAjdk=
</HostId>
</Error>