有没有一种方法可以解密Python中的jpg或png文件,这些文件使用JAVA-AmazonS3EncryptionClient加密CSE-KMS并存储在S3中?看起来boto3和aws ecryption客户端只支持密码文本,而不支持文件。在
我试过下面的代码但是失败了
def get_decrypted_stream(s3_object):
region_name = 'us-east-1'
encryptedImageBytes = s3_object.get()['Body'].read()
print("Decoded file : {}".format(encryptedImageBytes))
client = boto3.client('kms', region_name=region_name)
response = client.decrypt( CiphertextBlob=encryptedImageBytes)
data = meta[u'Plaintext']
return io.BytesIO(data)
错误:
它失败了“客户端.解密(CiphertextBlob=encryptedImage)“with{“errorMessage”:“调用解密操作时发生错误(413):HTTP内容长度超过200000字节。”,“errorType”:“ClientError”,}
参考文献: https://docs.aws.amazon.com/kms/latest/APIReference/API_Decrypt.htmlhttps://github.com/aws/aws-encryption-sdk-python/https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/python-example-code.htmlhttps://aws-encryption-sdk-python.readthedocs.io/en/latest/
根据您共享的文档,}API的最大负载限制为4k:https://docs.aws.amazon.com/kms/latest/APIReference/API_Encrypt.html
Encrypt
和{当使用KMS密钥对文件进行编码时,其原理是生成一个符号密钥,用符号密钥对有效负载进行编码,用KMS
encrypt
API对符号密钥进行编码,并将加密的符号密钥存储在信封中,例如在S3上作为元数据。在以下是S3文件加密的代码示例:
以及要解密的示例代码:
^{pr2}$相关问题 更多 >
编程相关推荐