1

我想为 spring-cloud-config 服务器设置 server.ssl.key-store-password ,配置将来自 GIT (application.yml)。

以下是我想在 application.yml 中配置的内容

server:
  port: 8760
  ssl:
    key-store: path to .jks
    key-store-password: '{cipher}encrypted password'
    key-store-type: jks
    key-password: '{cipher}encrypted password'

在引导配置服务器时,它使用 TextEncryptor FailsafeTextEncryptor 配置 EncryptionBootstrapConfiguration,当为​​ EnvironmentDecryptApplicationInitializer 调用解密函数时,它会失败。

我们如何为 EncryptionBootstrapConfiguration 自定义 TextEncryptor 以便我可以在启动 config-server 时使用 {cipher}

参考https://stackoverflow.com/a/32047393/1946403

4

1 回答 1

0

我收到了这个错误。要修复它,我必须将 EncryptionConfiguration 和 TextEncryptor 添加到 spring.factory 文件中。

我有 3 个文件:

加密配置:

@Configuration
public class AESEncryptionConfiguration {

    @Bean
    EnvironmentDecryptApplicationInitializer environmentDecryptApplicationInitializer() {
        return new EnvironmentDecryptApplicationInitializer(new AESTextEncryptor());
    }
}

文本加密器:

@Component
public class AESTextEncryptor implements TextEncryptor {

    @Override
    public String encrypt(String text) {
        .
        .
        .       
    }

    @Override
    public String decrypt(String encryptedText) {
        .
        .
        .
    }
}

然后我不得不添加对这两个文件的引用/src/main/resources/META-INF/spring.factories

org.springframework.cloud.bootstrap.BootstrapConfiguration=com.rs.config.AESEncryptionConfiguration,com.common.encryption.AESTextEncryptor

通过这样做,我能够创建自定义密码。

于 2017-01-07T18:19:30.647 回答