gpt4 book ai didi

scala - 如何在带有加密密码的 Scala 中使用 Typesafe 的配置

转载 作者:行者123 更新时间:2023-12-04 00:38:54 29 4
gpt4 key购买 nike

我想用 Typesafe's Config在我的项目中,但我不希望在任何集成或生产服务器的文件系统上的任何文件中使用任何明文密码。另外,我不想使用 environment variables to store clear text passwords .

理想情况下,我想要一个类似于 Jasypt 的解决方案。 EncryptablePropertyPlaceholderConfigurer可用于 Spring,这将允许我将某些属性值指定为加密,并在将值传递给应用程序之前让配置系统自动解密它们。我想使用 JCE keystore 来存储 key 并将其传递到我的应用程序中,但我也愿意使用其他使用数据库来存储 key 的工具。

有没有人设法让 Typesafe Config 项目以这种方式工作?

更新:sourcedelica 批评依赖于将 key 作为环境变量传递的解决方案是完全正确的。我改变了我的问题以请求使用更安全的 key 处理方式的解决方案。

最佳答案

你可以尝试拉皮条类型安全 Config类像这样:

object ConfigPimping{
implicit class RichConfig(conf:Config){
def getPasswordString(path:String, encryptKey:String):String = {
val encrypted = conf.getString(path)
val decrypted = ... //do decripy logic of your choice here
decrypted
}
}
}

object ConfigTest{
import ConfigPimping._
def main(args: Array[String]) {
val conf = ConfigFactory.load()
val myPass = conf.getPasswordString("myPass", "myDecryptKey")
}
}

那么,只要 RichConfig始终导入并可用,您可以通过 getPasswordString 访问您的自定义密码解密逻辑。功能。

关于scala - 如何在带有加密密码的 Scala 中使用 Typesafe 的配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16241165/

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