简体   繁体   English

如何使用 DynamoDB 加密客户端为 Java 加密 DynamoDB 列

[英]How do I encrypt a DynamoDB column using DynamoDB Encryption Client for Java

I'm trying to encrypt data being saved into a dynamo table.我正在尝试加密保存到发电机表中的数据。 This is production PII data that shouldn't be visible even to someone with permissions to view the table data.这是生产 PII 数据,即使对具有查看表数据权限的人也不应该可见。 Things like social security numbers.社会安全号码之类的东西。 I'm trying to follow the example here .我正在尝试按照此处的示例进行操作。

This is my code:这是我的代码:

AmazonDynamoDBClient client = new AmazonDynamoDBClient();
AWSKMS kmsClient = AWSKMSClientBuilder.defaultClient();
DirectKmsMaterialProvider cmp = new DirectKmsMaterialProvider(kmsClient, "my-key-arn");
DynamoDBEncryptor encryptor = DynamoDBEncryptor.getInstance(cmp);
DynamoDBMapper mapper = new DynamoDBMapper(client, DynamoDBMapperConfig.builder().withSaveBehavior(
    SaveBehavior.PUT).build(),
    new AttributeEncryptor(encryptor));


Customer customer = new Customer();
customer.setCustomerId("some-id");

//set some other values
...

mapper.save(customer);

The customer is saved to the DB but nothing is encrypted and everything is visible.客户已保存到数据库中,但没有任何内容被加密并且所有内容都是可见的。 What am I doing wrong?我究竟做错了什么?

You haven't encrypted anything.你还没有加密任何东西。 Follow step 5:按照步骤 5:

final EnumSet<EncryptionFlags> signOnly = EnumSet.of(EncryptionFlags.SIGN);
final EnumSet<EncryptionFlags> encryptAndSign = EnumSet.of(EncryptionFlags.ENCRYPT, EncryptionFlags.SIGN);
final Map<String, Set<EncryptionFlags>> actions = new HashMap<>();

for (final String attributeName : record.keySet()) {
  switch (attributeName) {
    case partitionKeyName: // fall through to the next case
    case sortKeyName:
      // Partition and sort keys must not be encrypted, but should be signed
      actions.put(attributeName, signOnly);
      break;
    case "test":
      // Neither encrypted nor signed
      break;
    default:
      // Encrypt and sign all other attributes
      actions.put(attributeName, encryptAndSign);
      break;
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM