Updating Spring Boot 2.1.7.RELEASE to 2.7.10 with SQL Server Always Encrypted Columns
In this article, we will discuss how to update a Spring Boot project from version 2.1.7.RELEASE to 2.7.10 and configure it to work with SQL Server databases that have columns encrypted using Always Encrypted. We will cover key concepts related to this topic, including Always Encrypted, Java Keystore, and necessary updates to the Spring Boot application.
What is Always Encrypted?
Always Encrypted is a feature in SQL Server that provides transparent encryption of sensitive data, ensuring data confidentiality at rest and in transit. With Always Encrypted, data is encrypted at the column level, and encryption and decryption are performed on the client side, leaving the database engine unaware of the encryption keys.
Java Keystore and Always Encrypted
To work with Always Encrypted columns in a Spring Boot application, you need to configure the Java Keystore, which is a repository of cryptographic keys, key pairs, and certificates. The Java Keystore is used to securely store the encryption keys required to access and manipulate Always Encrypted columns.
Updating Spring Boot Application
To update your Spring Boot application from version 2.1.7.RELEASE to 2.7.10, follow these steps:
Update the
spring-boot-dependenciesBOM in your project's pom.xml file.<dependencyManagement> ... <dependencies> ... <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>2.7.10</version> <type>pom</type> <scope>import</scope> </dependency> ... </dependencies> </dependencyManagement>Update the Spring Boot starter parent in your project's pom.xml file.
<parent> ... <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.7.10</version> <relativePath>/path/to/parent</relativePath> </parent>Update the Spring Boot starters and other dependencies used in your project.
<dependencies> ... <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> ... </dependencies>
Configuring Spring Boot with SQL Server and Always Encrypted
To configure the Spring Boot application to work with SQL Server and Always Encrypted columns, follow these steps:
Create a Java Keystore and import the encryption keys required for the Always Encrypted columns.
keytool -importkeystore -srckeystore sourcekeystore.p12 -srcstoretype pkcs12 -destkeystore keystore.jks -deststoretype JKSConfigure the Spring Boot application's
application.propertiesorapplication.ymlfile with the necessary JDBC connection properties, including the path to the Java Keystore, keystore password, and alias for the encryption key.<!-- application.properties --> spring.datasource.url=jdbc:sqlserver://server-name.database.windows.net:1433;databaseName=database-name;columnEncryption=enabled; spring.datasource.username=user-name spring.datasource.password=password spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver spring.datasource.ssl=true spring.jpa.show-sql=true spring.jpa.hibernate.ddl-auto=none spring.datasource.jdbc-url=jdbc:sqlserver://server-name.database.windows.net:1433;databaseName=database-name;columnEncryption=enabled;ssl=true;trustServerCertificate=true; spring.datasource.jdbc-properties.trustServerCertificate=true spring.datasource.jdbc-properties.keyStoreLocation=classpath:keystore.jks spring.datasource.jdbc-properties.keyStorePassword=password spring.datasource.jdbc-properties.keyStoreType=JKS spring.datasource.jdbc-properties.keyStoreAlias=alias
Always Encrypted is a feature in SQL Server that provides transparent encryption of sensitive data.
Java Keystore is used to securely store the encryption keys required to access and manipulate Always Encrypted columns.
To update a Spring Boot application from 2.1.7.RELEASE to 2.7.10, update the
spring-boot-dependenc