Java Magazine, Nov/Dec 2017
ORACLE COM JAVAMAGAZINE NOVEMBER DECEMBER 2017 49 java ee 8 Suppose that I wanted to encrypt the values that are contained in the creditLimit field of a Customer entity when it is persisted To implement such a process the values would need to be encrypted prior to being persisted and unencrypted upon retrieval from the database This can be done within a converter and by using JPA 22 I can inject an encryption object into the converter to achieve the desired result Listing 3 provides an example Listing3 @ Converter public class CreditLimitConverter implements AttributeConverter BigDecimal BigDecimal @ Inject CreditLimitEncryptor encryptor @ Override public BigDecimal convertToDatabaseColumn BigDecimal entityValue String encryptedFormat encryptor base64encode entityValue toString return BigDecimal valueOf Long valueOf encryptedFormat In this code the process is performed by injecting the CreditLimitEncryptor class into the converter and making use of it to assist in the process
You must have JavaScript enabled to view digital editions.