【发布时间】:2020-10-13 13:31:49
【问题描述】:
我有一个 spring 云配置服务器,它使用密钥库来解密来自 git 服务器的值。如果我使用文件路径引用密钥库,它会按预期工作并解密 {cipher} 值。但是,如果我尝试从类路径加载密钥库,它将停止处理此错误: CipherEnvironmentEncryptor.decrypt - 无法解密密钥:用户名(类 java.lang.IllegalStateException:无法从存储区加载密钥:类路径资源 [mykey.p12])
我在类而不是 yaml 上设置加密属性,因为我需要从外部保管库系统中查找 dev/prod 密钥库的不同密码。
我还可以在构建后在 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>
【问题讨论】:
标签: spring encryption spring-cloud