【发布时间】:2019-08-07 11:06:56
【问题描述】:
同学们,你能帮忙用jasypt从属性文件中解密密码(它是stmCredentials映射中的一个值)吗?
我的属性文件中有下一个字符串:
creds.users={testLogin: 'ENC(w0H***pgsj)'}
user2.login = ENC(9j3fHz5c****cLRCVvLTQmr5)
user2.pass = ENC(w0HxpKq7V3Lf***g3zs/hpgsj)
我在调试模式下运行测试:
@RunWith(SpringRunner.class)
@SpringBootTest
@ActiveProfiles("dev")
@Slf4j
public class CredentialsTest {
@BeforeClass
public static void beforeClass(){
System.setProperty("jasypt.encryptor.password", "C*******L");
}
@Autowired
StmCredentials stmCredentials;
@Value("${user2.login}")
private String user2Login;
@Value("${user2.pass}")
private String user2Pass;
@Test
public void getCredspairs() {
HashMap<String, String> credspairs = stmCredentials.getCredspairs();
}
}
运行后我在变量中有下一个值:
credspairs:
key: "testLogin"
value:"ENC(w0HxpKq7V3LfEPsU5mbd0Vg3zs/hpgsj)" //it wasn't decrypt =(
和(注意!)
user2Login = testLogin //it was decrypt
user2Pass = K1212Zrde
我的属性文件中似乎有问题,在creds.users 属性中。我尝试使用“单引号,双引号”,但没有帮助。
StmCredentials bean 看起来像:
@Component
@EnableConfigurationProperties
public class StmCredentials {
@Value("#{${creds.users}}")
private HashMap<String, String> credspairs;
public HashMap<String, String> getCredspairs() {
return credspairs;
}
public void setCredspairs(HashMap<String, String> somedata) {
this.credspairs = somedata;
}
}
如何解密存储在StmCredentials(值)中的密码?
谢谢你的建议。
【问题讨论】:
标签: spring-boot properties-file jasypt