我有一个spring云配置服务器,它使用keystore来解密来自git服务器的值。如果我使用文件路径引用密钥库,它会按预期工作,并解密{cipher}值。但是,如果我尝试从类路径加载密钥库,它将停止工作,并显示以下错误: CipherEnvironmentEncryptor.decrypt -无法解密密钥:用户名(类java.lang.IllegalStateException:无法从存储:类路径资源mykey.p12加载密钥)
我正在设置类的加密属性,而不是yaml,因为我需要从dev/prod密钥库的外部vault系统中查找不同的密码。
在构建之后,我还可以在target/classes下看到p.12文件,因此它在构建过程中不会被过滤掉。不知道我错过了什么。
SpringApplication sa = new SpringApplication(Myclass.class);
Properties springProperties = new Properties();
springProperties.setProperty("encrypt.enabled", "true");
springProperties.setProperty("encrypt.key-store.location", "file:///Users/user/IdeaProjects/project/src/main/resources/configuration/mykey.p12"); //working fine
springProperties.setProperty("encrypt.key-store.location", "classpath:/configuration/mykey.p12"); //does not work
springProperties.setProperty("encrypt.key-store.type", "PKCS12");
springProperties.setProperty("encrypt.key-store.password", "password");
springProperties.setProperty("encrypt.key-store.secret", "password");
springProperties.setProperty("encrypt.key-store.alias", "vault");
sa.setDefaultProperties(springProperties);
sa.run(args);使用
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
<version>2.2.0.RELEASE</version>
<name>spring-cloud-config-server</name>发布于 2020-10-14 03:42:09
我的问题实际上与此相关:generated certificate stops working when moved to resources folder
我对资源进行了maven过滤配置,这会破坏最终的p12文件。现在,我只需要将需要过滤的文件移到另一个资源目录,它就可以工作了。
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<directory>src/main/resources-filtered</directory>
<filtering>true</filtering>
<includes>
<include>*.yml</include>
<include>logback.xml</include>
</includes>
</resource>
</resources>https://stackoverflow.com/questions/64336172
复制相似问题