首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring cloud从classpath vs file加载keystore

Spring cloud从classpath vs file加载keystore
EN

Stack Overflow用户
提问于 2020-10-13 21:31:50
回答 1查看 479关注 0票数 1

我有一个spring云配置服务器,它使用keystore来解密来自git服务器的值。如果我使用文件路径引用密钥库,它会按预期工作,并解密{cipher}值。但是,如果我尝试从类路径加载密钥库,它将停止工作,并显示以下错误: CipherEnvironmentEncryptor.decrypt -无法解密密钥:用户名(类java.lang.IllegalStateException:无法从存储:类路径资源mykey.p12加载密钥)

我正在设置类的加密属性,而不是yaml,因为我需要从dev/prod密钥库的外部vault系统中查找不同的密码。

在构建之后,我还可以在target/classes下看到p.12文件,因此它在构建过程中不会被过滤掉。不知道我错过了什么。

代码语言:javascript
复制
    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);

使用

代码语言:javascript
复制
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
<version>2.2.0.RELEASE</version>
<name>spring-cloud-config-server</name>
EN

回答 1

Stack Overflow用户

发布于 2020-10-14 03:42:09

我的问题实际上与此相关:generated certificate stops working when moved to resources folder

我对资源进行了maven过滤配置,这会破坏最终的p12文件。现在,我只需要将需要过滤的文件移到另一个资源目录,它就可以工作了。

代码语言:javascript
复制
<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>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64336172

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档