我已经成功地使用了默认的jasypt配置来加密Springboot中数据库连接的密码。然而,我非常喜欢把“秘密”存储在罐子里,而不是在环境中。我从文档中使用了一个自定义的StringEncryptor类。
@Bean(name = "jasyptStringEncryptor")
public StringEncryptor getPasswordEncryptor() {
PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor();
SimpleStringPBEConfig config = new SimpleStringPBEConfig();
config.setPassword("verybigsecret");
config.setAlgorithm("PBEWITHHMACSHA512ANDAES_256");
config.setKeyObtentionIterations("1000");
config.setPoolSize("1");
config.setProviderName("SunJCE");
config.setSaltGeneratorClassName("org.jasypt.salt.RandomSaltGenerator");
config.setStringOutputType("base64");
encryptor.setConfig(config);
return encryptor;
}
然后使用mvn目标在资源文件中插入加密的密钥(也可以使用application。properties)
mvn jasypt:encrypt -Djasypt.encryptor.password=verybigpassword -Djasypt.plugin.path="file:src/main/resources/default.properties" -Djasypt.encryptor.StringEncryptor=jasyptStringEncryptor
然而,我得到这个错误,表明目标无法找到自定义bean
[INFO] No active profile set, falling back to default profiles: default
[INFO] Post-processing PropertySource instances
[INFO] Converting PropertySource configurationProperties [org.springframework.boot.context.properties.source.ConfigurationPropertySourcesPropertySource] to AOP Proxy
[INFO] Converting PropertySource systemProperties [org.springframework.core.env.PropertiesPropertySource] to EncryptableMapPropertySourceWrapper
[INFO] Converting PropertySource systemEnvironment [org.springframework.boot.env.SystemEnvironmentPropertySourceEnvironmentPostProcessor$OriginAwareSystemEnvironmentPropertySource] to EncryptableSystemEnvironmentPropertySourceWrapper
[INFO] Converting PropertySource random [org.springframework.boot.env.RandomValuePropertySource] to EncryptablePropertySourceWrapper
[INFO] Property Filter custom Bean not found with name 'encryptablePropertyFilter'. Initializing Default Property Filter
[INFO] Started MavenCli in 0.456 seconds (JVM running for 1.403)
[INFO] Active Profiles: Default
[INFO] Encrypting file src/main/resources/default.properties
[INFO] String Encryptor custom Bean not found with name 'jasyptStringEncryptor'. Initializing Default String Encryptor
[INFO] Encryptor config not found for property jasypt.encryptor.algorithm, using default value: PBEWITHHMACSHA512ANDAES_256
我已经在这个问题上工作了一段时间,但找不到问题-我猜它是明显的,但我无法看到它。任何援助赞赏!