2016-08-10 8 views
0

AWS IAMで作成したキーでアプリケーションのpdfファイルを暗号化し、S3に暗号化ファイルをアップロードしようとしています。私はこれを達成するためにboto3を使用します。私は暗号化せずにS3にファイルをアップロードすることができます。botocore.exceptions.ClientError:クライアントサイドKMS暗号化

botocore.exceptions.ClientError:私はこの次のエラーを取得する

def write(self): 
    print 'Write to S3' 
    client = boto3.client('kms') 

    s3 = boto3.client('s3') 
    input_file = open('265987747.pdf', 'rb') 
    data = input_file.read() 
    input_file.close() 
    print type(data) 
    response = client.encrypt(
     KeyId='alias/efax', 
     Plaintext=data, 
     EncryptionContext={ 
      'string': 'string' 
     } 
    ) 
    #Upload file to S3 
    #s3.upload_file("265987747.pdf", "bucket_efax", "265987747.pdf") 

:ここでは、暗号化を行い、私の関数であるエラーが検出された1つの検証:値の誤差は(にValidationException)暗号化操作を呼び出すときに発生しました「平文」の制約が満たされませんでした。メンバーの長さが4096以下である必要があります。

KMSでファイルを暗号化する正しい方法を使用しているかどうかわかりません。

答えて

0

おそらく4KBを超えるデータを暗号化しようとしています。

ドキュメントには、4 KBを超えることはできません(エラーもその点を指摘しています)。

You can encrypt up to 4 KB of arbitrary data such as an RSA key, a database password, or other sensitive customer information.

If you are moving encrypted data from one region to another, you can use this API to encrypt in the new region the plaintext data key that was used to encrypt the data in the original region. This provides you with an encrypted copy of the data key that can be decrypted in the new region and used there to decrypt the encrypted data.

は、詳細は私の知る限りのbotoはまだファイルのクライアント側の暗号化をサポートしていません覚えているよう

ためdocsを参照してください。

自分で暗号化してs3に送信する必要があります。私はクライアント側の暗号化のための小さなコードを実装しましたhere djangoファイルフィールド。希望があれば

関連する問題