【问题标题】:How to upload encrypted data to S3?如何将加密数据上传到 S3?
【发布时间】:2018-06-16 07:22:17
【问题描述】:

我正在尝试将加密数据上传到 S3。此代码成功加密数据,但会将原始未加密文件上传到 S3。我如何告诉它上传加密数据?

注意-注释的解密行用于测试数据是否已正确加密和解​​密

session = botocore.session.get_session()
client = session.create_client('kms', 
                               region_name = 'us-east-1', 
                               aws_access_key_id = '[YOUR ACCESS KEY]', 
                               aws_secret_access_key = '[YOUR SECRET ACCESSKEY]')

key_id = '[KEY ID]'
plaintext='[FILEPATH\FILENAME.CSV]'



ciphertext = client.encrypt(KeyId=key_id, Plaintext=plaintext)
#decrypt_ciphertext = client.decrypt(CiphertextBlob = 
ciphertext['CiphertextBlob'])
print('Ciphertext: ', ciphertext)
#print('Decrypted Ciphertext: ', decrypt_ciphertext) 


s3 = boto3.client('s3',
         aws_access_key_id='[YOUR ACCESS KEY]',
         aws_secret_access_key='[YOUR SECRET ACCESS KEY]')

filename = '[FILEPATH\FILENAME.CSV]'
bucket_name = '[BUCKET NAME]'

# Uploads the given file using a managed uploader, which will split up large
# files automatically and upload parts in parallel.
s3.upload_file(filename, bucket_name, filename)

【问题讨论】:

    标签: amazon-web-services encryption amazon-s3 file-upload botocore


    【解决方案1】:

    KMS encrypt() command对文件起作用。相反,它接受Plaintext 中的传入文本,并在CiphertextBlob 中输出加密文本。

    您的代码负责读取源文件并将内容传递给encrypt(),然后负责将内容写入磁盘。

    另见:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-04
      • 2018-09-07
      • 2012-12-09
      • 2023-03-25
      • 1970-01-01
      • 2016-05-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多