使用Python加密DynamoDB表条目时发生异常

时间:2019-07-19 15:19:15

标签: python-3.x encryption amazon-dynamodb

我正在尝试使用Python创建加密表并插入行。由于某种原因,我收到此错误。 “ dynamodb_encryption_sdk.exceptions.WrappingError:无法使用AWS KMS生成资料”

这是我的代码-已验证签名的正确性。可能是别的东西。请看看并提出建议-

import boto3
from boto3.dynamodb.types import Binary

from dynamodb_encryption_sdk.encrypted.table import EncryptedTable
from dynamodb_encryption_sdk.identifiers import CryptoAction
from dynamodb_encryption_sdk.material_providers.aws_kms import AwsKmsCryptographicMaterialsProvider
from dynamodb_encryption_sdk.material_providers.most_recent import MostRecentProvider
from dynamodb_encryption_sdk.material_providers.store.meta import MetaStore
from dynamodb_encryption_sdk.structures import AttributeActions
from dynamodb_encryption_sdk.encrypted.item import decrypt_python_item, encrypt_python_item

dynamodb = boto3.resource('dynamodb', aws_access_key_id='XXXX', aws_secret_access_key='YYYY')
table = dynamodb.Table('test')

aws_cmk_id='ZZZZ'
aws_kms_cmp = AwsKmsCryptographicMaterialsProvider(key_id=aws_cmk_id)

actions = AttributeActions(
    default_action=CryptoAction.ENCRYPT_AND_SIGN,
    attribute_actions={'example': CryptoAction.DO_NOTHING}
)


encrypted_table = EncryptedTable(
    table=table,
    materials_provider=aws_kms_cmp,
    attribute_actions=actions
)

plaintext_item = {
        'partition_attribute': 'value1',
        'clientid' : '4',
        'sort_attribute': 55,
        'example': 'data',
        'numbers': 99,
        'test1': 'test-value'
}

encrypted_table.put_item(Item=plaintext_item)
encrypted_table.get_item(Item=plaintext_item)

期望它在表中插入加密的文本

0 个答案:

没有答案