使用python AWS sdk(boto3),如何解密由ses保存的电子邮件

时间:2017-06-08 22:27:57

标签: python amazon-web-services amazon-s3 boto3 amazon-ses

我的设置是这样的:使用AWS,我有一个SES规则,可以通过加密将传入的电子邮件保存在s3存储桶中。当我使用java sdk进行阅读时,使用此example

进行读取没有任何问题

当尝试使用AWS python api阅读它时,我不断获得InvalidCiphertextException。这是我的python程序:

import boto3
s3 = boto3_resource('s3')
kms = boto3_client('kms')
obj = s3.Object('my_bucket_name', 'my_object_key').get()

body=obj['Body'].read()

t = kms.decrypt(
    CiphertextBlob=blob,
    EncryptionContext ={

        "aws:ses:message-id" : "<my_message_id>",
        "aws:ses:source-account" : "<my_account-number>",
        "kms_cmk_id" : "<kms_cmk_id>",
        "aws:ses:rule-name" : "<my_ses_rule>"
    }
)
print t['Plaintext'] 

这是堆栈跟踪:

 - File "C:\Users\yigal\git\receipt-email-archive-api\playground.py", line 101, in read_encrypted2
    "aws:ses:rule-name" : "VERIFONE_rule"
 - File "C:\Python27\lib\site-packages\botocore\client.py", line 253, in _api_call
    return self._make_api_call(operation_name, kwargs)
 - File "C:\Python27\lib\site-packages\botocore\client.py", line 557, in _make_api_call
    raise error_class(parsed_response, operation_name)
 - InvalidCiphertextException: An error occurred (InvalidCiphertextException) when calling the Decrypt operation:

1 个答案:

答案 0 :(得分:0)

您的变量“ blob”为空,因为您读入的变量称为“ body”