Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Playframework 在application.conf中加密数据库密码_Playframework - Fatal编程技术网

Playframework 在application.conf中加密数据库密码

Playframework 在application.conf中加密数据库密码,playframework,Playframework,Play framework[我使用的是v1.2.3]不支持application.conf中存储的db密码加密。这将存储为纯文本文件。DBPlugin读取此属性并创建连接池 要求加密此密码-例如使用。一些企业将此作为安全措施执行 有人试过这样做吗 因为DBPlugin是在ApplicationStart上加载的,所以没有办法破解它。这就需要编写一个自定义插件,并为application.conf属性的db.password设置一个新值 有什么建议吗?问题是应该使用哪个密码来加密密码?如果使用默

Play framework[我使用的是v1.2.3]不支持application.conf中存储的db密码加密。这将存储为纯文本文件。DBPlugin读取此属性并创建连接池

要求加密此密码-例如使用。一些企业将此作为安全措施执行

有人试过这样做吗

因为DBPlugin是在ApplicationStart上加载的,所以没有办法破解它。这就需要编写一个自定义插件,并为application.conf属性的db.password设置一个新值


有什么建议吗?

问题是应该使用哪个密码来加密密码?如果使用默认密码,也不安全。如果将其放入配置文件,则会出现递归问题。我看到的唯一解决方案是使用存储密码的插件,并更改应用程序属性中的值。这样,密码就可以安全地存储起来。至少在Play1.x中。

最后我通过编写一个Play插件解决了这个问题。编写Play插件也很容易。 以下是示例代码:

package plugin;

import java.util.Properties;

import org.jasypt.util.text.StrongTextEncryptor;

import play.Play;
import play.PlayPlugin;

public class DBPasswordInject extends PlayPlugin {

    @Override
    public void onConfigurationRead() {
        StrongTextEncryptor strongTextEncryptor = new StrongTextEncryptor();
        strongTextEncryptor.setPassword("$Look##$2");// this password has been used to encrypt

        String encryptedPassword = Play.configuration.getProperty("db.pass");
        String decrypted = strongTextEncryptor.decrypt(encryptedPassword);
        Play.configuration.setProperty("db.pass", decrypted); //override

        super.onConfigurationRead();
    }

}

唯一的缺点是我无法使用org.jasypt.util.password.StrongPasswordEncryptor,因为没有解密方法。

有趣的问题,您也可以在上发布此消息,以确保获得最大的覆盖率。jasypt允许在运行时从system env或java属性中查找加密密码。该密码永远不需要签入源代码管理系统,也不需要突出显示循环问题。请永远不要在命令行中输入密码。如果使用另一个propertyfile,则可以直接使用播放功能。如果使用org.jasypt.encryption.StringEncryptor类,则可以同时访问加密和解密