繁体   English   中英

如何清除Jasypt Java库建议的环境变量?

[英]How to clear environment variable suggested by Jasypt Java library?

Jasypt建议将主密钥传递给Java应用程序的一种方法是通过环境变量

jasypt在该网页中建议:

例如,这将允许用户在环境变量中设置加密密码,启动应用程序或应用程序服务器,让jasypt加密器对象初始化,然后取消设置变量(从而将其隐藏)

如何完成“重置变量”部分?

我最终遵循@Andreas的建议,即从文件中读取主密钥(理想情况下应具有限制性权限)。

为了保持Jasypt Spring集成的优势,我制作了一个自定义“ FilePBEConfig”:

package com.my.product;

import org.jasypt.encryption.pbe.config.SimplePBEConfig;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class FilePBEConfig extends SimplePBEConfig {
    private String passwordFilePath = null;

    public FilePBEConfig() {
        super();
    }

    public String getPasswordFilePath() {
        return passwordFilePath;
    }

    public void setPasswordFilePath(final String passwordFilePath) throws IOException {
        this.passwordFilePath = passwordFilePath;
        if (passwordFilePath == null) {
            super.setPassword(null);
        } else {
            try (BufferedReader br = new BufferedReader(new FileReader(passwordFilePath))) {
                super.setPassword(br.readLine());
            }
        }
    }
}

然后,您可以按照Jasypt Spring Integration的建议在Spring xml文件中使用它:

 <bean id="fileConfiguration"
     class="com.my.product.FilePBEConfig">
   <property name="algorithm" value="PBEWithMD5AndDES" />
   <property name="passwordFilePath" value="/path/to/masterfile" />
 </bean>

暂无
暂无

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

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