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