更新时间:2023-09-09 19:01:10
我提供了一些基本指南,如下所示.
您需要在属性文件中添加以下两个参数才能使应用程序正常工作.这是假设您使用默认加密算法进行加密.如果您正在使用其他一些,请确保相应地更改它.
jasypt.encryptor.iv-generator-classname=org.jasypt.iv.NoIvGeneratorjasypt.encryptor.algorithm=PBEWithMD5AndDES
可以参考更多详情https://nirmalbalasooriya.blogspot.com/2020/02/spring-boot-property-encryption-using.html
I am using Spring auto configuration to connect to database. For that i added below properties in properties file:
spring.datasource.url=jdbc:oracle:thin:@ABCDE2D.com:1888:ABCDE2D1
spring.datasource.username=user
spring.datasource.password=password
spring.datasource.driver-class-oracle.jdbc.driver.OracleDriver
In my dao class, i have @Autowired NamedParameterJdbcTemplate and using it directly to get data from database.
Till here it is working fine.
Now i need to encrypt the password in properties file. For that i did the below:
- Added jasypt-spring-boot-starter in pom
- Added spring.datasource.password=ENC(NoIv2c+WQYF3LenN0tDYPA==) in properties file
- Added jasypt.encryptor.password=key in properties file
Now i am getting the below error:
Failed to bind properties under 'spring.datasource.password' to
java.lang.String:
Reason: Failed to bind properties under 'spring.datasource.password' to
java.lang.String
I'm providing some basic guide as follows.
You need to add following two parameters in to property file in order application to work properly. This is assuming you are encrypting using default encryption algorithm. If you are useing some other, then make sure to change it accordingly.
jasypt.encryptor.iv-generator-classname=org.jasypt.iv.NoIvGenerator jasypt.encryptor.algorithm=PBEWithMD5AndDES
You can refer to more details https://nirmalbalasooriya.blogspot.com/2020/02/spring-boot-property-encryption-using.html