Encryption

Background

The configuration method for Spring Boot Starter Data Encryption is suitable for business scenarios using SpringBoot and can make the most of SringBoot’s configuration initialization and Bean management capabilities to complete the creation of ShardingSphereDataSource objects, reducing unnecessary coding work.

Parameters

  1. spring.shardingsphere.datasource.names= # Omit the data source configuration, please refer to the usage
  2. spring.shardingsphere.rules.encrypt.tables.<table-name>.query-with-cipher-column= # Whether the table uses cipher columns for query
  3. spring.shardingsphere.rules.encrypt.tables.<table-name>.columns.<column-name>.cipher-column= # Cipher column name
  4. spring.shardingsphere.rules.encrypt.tables.<table-name>.columns.<column-name>.assisted-query-column= # Assisted query column name
  5. spring.shardingsphere.rules.encrypt.tables.<table-name>.columns.<column-name>.plain-column= # Plain column name
  6. spring.shardingsphere.rules.encrypt.tables.<table-name>.columns.<column-name>.encryptor-name= # Encrypt algorithm name
  7. # Encrypt algorithm configuration
  8. spring.shardingsphere.rules.encrypt.encryptors.<encrypt-algorithm-name>.type= # Encrypt algorithm type
  9. spring.shardingsphere.rules.encrypt.encryptors.<encrypt-algorithm-name>.props.xxx= # Encrypt algorithm properties
  10. spring.shardingsphere.rules.encrypt.queryWithCipherColumn= # Whether query with cipher column for data encrypt. User you can use plaintext to query if have

Please refer to Built-in Encrypt Algorithm List for more details about type of algorithm.

Procedure

  1. Configure the data encryption rules in the SpringBoot file, including the data source, encryption rules, global properties and other items.
  2. Start the SpringBoot program, which will automatically load the configuration and initialize the ShardingSphereDataSource.

Sample

  1. spring.shardingsphere.datasource.names=ds
  2. spring.shardingsphere.datasource.ds.type=com.zaxxer.hikari.HikariDataSource
  3. spring.shardingsphere.datasource.ds.driver-class-name=com.mysql.jdbc.Driver
  4. spring.shardingsphere.datasource.ds.jdbc-url=jdbc:mysql://localhost:3306/demo_ds?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
  5. spring.shardingsphere.datasource.ds.username=root
  6. spring.shardingsphere.datasource.ds.password=
  7. spring.shardingsphere.rules.encrypt.encryptors.name-encryptor.type=AES
  8. spring.shardingsphere.rules.encrypt.encryptors.name-encryptor.props.aes-key-value=123456abc
  9. spring.shardingsphere.rules.encrypt.encryptors.pwd-encryptor.type=AES
  10. spring.shardingsphere.rules.encrypt.encryptors.pwd-encryptor.props.aes-key-value=123456abc
  11. spring.shardingsphere.rules.encrypt.tables.t_user.columns.username.cipher-column=username
  12. spring.shardingsphere.rules.encrypt.tables.t_user.columns.username.encryptor-name=name-encryptor
  13. spring.shardingsphere.rules.encrypt.tables.t_user.columns.pwd.cipher-column=pwd
  14. spring.shardingsphere.rules.encrypt.tables.t_user.columns.pwd.encryptor-name=pwd-encryptor
  15. spring.shardingsphere.props.query-with-cipher-column=true
  16. spring.shardingsphere.props.sql-show=true