Spring-Cloud-Config 服务器的自定义加密/解密 [英] Custom Encryption/Decryption for Spring-Cloud-Config Server

查看:42
本文介绍了Spring-Cloud-Config 服务器的自定义加密/解密的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 spring-cloud-config 服务器并尝试使用加密/解密功能.有没有办法自定义加密/解密功能,即我们确实有自己的加密标准并希望利用这些库.

I am using spring-cloud-config server and trying to use the encrypt/decrypt feature. Is there a way we can customize the encrypt/decrypt feature i.e. we do have our own encryption standards and want to leverage those libraries.

提前感谢任何帮助.

推荐答案

如果你想自定义加密/解密,本质上你需要自定义 org.springframework.security.crypto.encrypt.TextEncryptor自己豆.

If you want to customize the encryption/decryption, essentially you need customize the org.springframework.security.crypto.encrypt.TextEncryptor bean by yourself.

乐观地,从 application.properties/application.yml 中删除所有 entrypt 相关的配置,并且您还需要确保 JCE 不在您的类路径中,主要建议是禁用 spring 默认加密自动配置,然后注册您的自己的 TextEncryptor bean.

Optimisticly, remove all the entrypt related configuration from your application.properties/application.yml, also you need make sure the JCE is not in your classpath, the main propose is disable the spring default encryption auto-configuration, then register your own TextEncryptor bean.

在这里,我添加了一个非常简单的示例,以便您可以使用现有库实现 MyTextEncryptor.

Here I add a very simple sample, so you can implement the MyTextEncryptor with your existing library.

示例

@SpringBootApplication
@EnableConfigServer
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    @Component
    static class MyTextEncryptor implements TextEncryptor {

        @Override
        public String encrypt(String text) {
            return "encrypt\n";
        }

        @Override
        public String decrypt(String encryptedText) {
            return "decrypt\n";
        }
    }
}

结果

参考:

org.springframework.cloud.bootstrap.encrypt.EncryptionBootstrapConfigurationorg.springframework.cloud.bootstrap.encrypt.EnvironmentDecryptApplicationInitializerorg.springframework.cloud.config.server.encryption.EncryptionController

这篇关于Spring-Cloud-Config 服务器的自定义加密/解密的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆