Source:
<code>public ObjectNode encryptAsync( ObjectNode itemJObj, EncryptionOptions encryptionOptions, DataEncryptionKeyProvider dataEncryptionKeyProvider) { assert (itemJObj != null); assert (encryptionOptions != null); assert (encryptionOptions.getPathsToEncrypt() != null); assert (!encryptionOptions.getPathsToEncrypt().isEmpty()); for (String path : encryptionOptions.getPathsToEncrypt()) { if (StringUtils.isEmpty(path) || path.charAt(0) != '/' || path.lastIndexOf('/') != 0) { throw new IllegalArgumentException("Invalid encryption path: " + path); } } if (encryptionOptions.getDataEncryptionKeyId() == null) { throw new IllegalArgumentException("Invalid encryption options: encryptionOptions.getDataEncryptionKeyId." + encryptionOptions.getDataEncryptionKeyId()); } if (encryptionOptions.getEncryptionAlgorithm() == null) { throw new IllegalArgumentException("Invalid encryption options: encryptionOptions.getEncryptionAlgorithm." + encryptionOptions.getEncryptionAlgorithm()); } if (dataEncryptionKeyProvider == null) { throw new IllegalArgumentException(RMResources.EncryptionKeyProviderNotConfigured); } ObjectNode toEncryptJObj = Utils.getSimpleObjectMapper().createObjectNode(); for (String pathToEncrypt : encryptionOptions.getPathsToEncrypt()) { <START> String propertyName = pathToEncrypt.substring(1); <END> JsonNode propertyValueHolder = itemJObj.get(propertyName); if (propertyValueHolder != null) { toEncryptJObj.set(propertyName, itemJObj.get(propertyName)); itemJObj.remove(propertyName); } } SensitiveDataTransformer serializer = new SensitiveDataTransformer(); byte[] plainText = serializer.toByteArray(toEncryptJObj); DataEncryptionKey dataEncryptionKey = dataEncryptionKeyProvider.loadDataEncryptionKey(encryptionOptions.getDataEncryptionKeyId(), encryptionOptions.getEncryptionAlgorithm()); EncryptionProperties encryptionProperties = new EncryptionProperties( 2, encryptionOptions.getEncryptionAlgorithm(), encryptionOptions.getDataEncryptionKeyId(), dataEncryptionKey.encryptData(plainText)); itemJObj.set(Constants.Properties.EncryptedInfo, encryptionProperties.toObjectNode()); return itemJObj; }</code><technical_language>work for nested JPath</technical_language>

Target:
public ObjectNode encryptAsync( ObjectNode itemJObj, EncryptionOptions encryptionOptions, DataEncryptionKeyProvider dataEncryptionKeyProvider) { assert (itemJObj != null); assert (encryptionOptions != null); assert (encryptionOptions.getPathsToEncrypt() != null); assert (!encryptionOptions.getPathsToEncrypt().isEmpty()); for (String path : encryptionOptions.getPathsToEncrypt()) { if (StringUtils.isEmpty(path) || path.charAt(0) != '/' || path.lastIndexOf('/') != 0) { throw new IllegalArgumentException("Invalid encryption path: " + path); } } if (encryptionOptions.getDataEncryptionKeyId() == null) { throw new IllegalArgumentException("Invalid encryption options: encryptionOptions.getDataEncryptionKeyId." + encryptionOptions.getDataEncryptionKeyId()); } if (encryptionOptions.getEncryptionAlgorithm() == null) { throw new IllegalArgumentException("Invalid encryption options: encryptionOptions.getEncryptionAlgorithm." + encryptionOptions.getEncryptionAlgorithm()); } if (dataEncryptionKeyProvider == null) { throw new IllegalArgumentException(RMResources.EncryptionKeyProviderNotConfigured); } ObjectNode toEncryptJObj = Utils.getSimpleObjectMapper().createObjectNode(); for (String pathToEncrypt : encryptionOptions.getPathsToEncrypt()) { String propertyName = pathToEncrypt.substring(1); JsonNode propertyValueHolder = itemJObj.get(propertyName); if (propertyValueHolder != null) { toEncryptJObj.set(propertyName, itemJObj.get(propertyName)); itemJObj.remove(propertyName); } } SensitiveDataTransformer serializer = new SensitiveDataTransformer(); byte[] plainText = serializer.toByteArray(toEncryptJObj); DataEncryptionKey dataEncryptionKey = dataEncryptionKeyProvider.getDataEncryptionKey(encryptionOptions.getDataEncryptionKeyId(), encryptionOptions.getEncryptionAlgorithm()); EncryptionProperties encryptionProperties = new EncryptionProperties( 2, encryptionOptions.getEncryptionAlgorithm(), encryptionOptions.getDataEncryptionKeyId(), dataEncryptionKey.encryptData(plainText)); itemJObj.set(Constants.Properties.EncryptedInfo, encryptionProperties.toObjectNode()); return itemJObj; }