gpt4 book ai didi

playframework - 在 application.conf 中加密数据库密码

转载 作者:行者123 更新时间:2023-12-04 02:05:58 26 4
gpt4 key购买 nike

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

要求是加密此密码 - 例如使用 Jasypt .一些企业将此作为一种安全措施。

有没有人试过做这样的事情?

由于 DBPlugin 在 ApplicationStart 上加载,因此无法破解它。剩下的就是编写一个自定义插件和 onConfigurationRead为 application.conf 属性的 db.password 设置一个新值。

有什么建议吗?

最佳答案

最后我通过编写一个 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 - 因为没有解密方法。

关于playframework - 在 application.conf 中加密数据库密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9200404/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com