### Question:
DynamoDbEncryptor implements DynamoDbEncryptionClient { public static Builder builder() { return new Builder(); } protected  DynamoDbEncryptor(EncryptionMaterialsProvider provider, String descriptionBase); protected  DynamoDbEncryptor(EncryptionMaterialsProvider provider); static Builder builder(); @Override Map<String, AttributeValue> encryptRecord(Map<String, AttributeValue> record,
                                                     DynamoDbEncryptionConfiguration configuration); @Override Map<String, AttributeValue> decryptRecord(Map<String, AttributeValue> record,
                                                     DynamoDbEncryptionConfiguration configuration);  }### Answer:
@Test(expectedExceptions = DynamoDbEncryptionException.class) public void fullEncryptionBadSignature() { Map<String, AttributeValue> encryptedAttributes = EncryptionTestHelper.encryptAllFieldsExcept(encryptor, Collections.unmodifiableMap(attribs), context, asList("hashKey", "rangeKey", "version")); assertThat(encryptedAttributes, AttrMatcher.invert(attribs)); Map<String, AttributeValue> modifiedEncryptedAttributes = new HashMap<>(encryptedAttributes); modifiedEncryptedAttributes.put("hashKey", AttributeValue.builder().n("666").build()); EncryptionTestHelper.decryptAllFieldsExcept(encryptor, Collections.unmodifiableMap(modifiedEncryptedAttributes), context, asList("hashKey", "rangeKey", "version")); }
@Test(expectedExceptions = DynamoDbEncryptionException.class) public void signedOnlyBadSignature() { Map<String, AttributeValue> encryptedAttributes = EncryptionTestHelper.encryptAllFieldsExcept(encryptor, attribs, context, attribs.keySet()); assertThat(encryptedAttributes, AttrMatcher.invert(attribs)); Map<String, AttributeValue> modifiedEncryptedAttributes = new HashMap<>(encryptedAttributes); modifiedEncryptedAttributes.put("hashKey", AttributeValue.builder().n("666").build()); EncryptionTestHelper.decryptAllFieldsExcept(encryptor, modifiedEncryptedAttributes, context, attribs.keySet()); }
@Test(expectedExceptions = DynamoDbEncryptionException.class) public void RsaSignedOnlyBadSignature() throws GeneralSecurityException { KeyPairGenerator rsaGen = KeyPairGenerator.getInstance("RSA"); rsaGen.initialize(2048, Utils.getRng()); KeyPair sigPair = rsaGen.generateKeyPair(); encryptor = new DynamoDbEncryptor( new SymmetricStaticProvider(encryptionKey, sigPair, Collections.emptyMap()), "encryptor-"); Map<String, AttributeValue> encryptedAttributes = EncryptionTestHelper.encryptAllFieldsExcept(encryptor, attribs, context, attribs.keySet()); assertThat(encryptedAttributes, AttrMatcher.invert(attribs)); Map<String, AttributeValue> modifiedEncryptedAttributes = new HashMap<>(encryptedAttributes); modifiedEncryptedAttributes.put("hashKey", AttributeValue.builder().n("666").build()); EncryptionTestHelper.decryptAllFieldsExcept(encryptor, modifiedEncryptedAttributes, context, attribs.keySet()); }
@Test(expectedExceptions = DynamoDbEncryptionException.class) public void EcdsaSignedOnlyBadSignature() throws GeneralSecurityException { encryptor = new DynamoDbEncryptor(getMaterialProviderwithECDSA()); Map<String, AttributeValue> encryptedAttributes = EncryptionTestHelper.encryptAllFieldsExcept(encryptor, attribs, context, attribs.keySet()); assertThat(encryptedAttributes, AttrMatcher.invert(attribs)); Map<String, AttributeValue> modifiedEncryptedAttributes = new HashMap<>(encryptedAttributes); modifiedEncryptedAttributes.put("hashKey", AttributeValue.builder().n("666").build()); EncryptionTestHelper.decryptAllFieldsExcept(encryptor, modifiedEncryptedAttributes, context, attribs.keySet()); }