繁体   English   中英

Spring Cloud 从类路径 vs 文件加载密钥库

[英]Spring cloud loading keystore from classpath vs file

我有一个 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>

我的问题实际上与此有关: 生成的证书在移动到资源文件夹时停止工作

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

<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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM