如何加密配置文件中的密码,grails [和java] [英] howto encrypt passwords in configuration files, grails [and java]

查看:263
本文介绍了如何加密配置文件中的密码,grails [和java]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找如何在grails中保护配置文件中的密码。这意味着在Config.groovy和DataSource.groovy中保护密码。有很多google的结果,包含一些片段的答案,但没有简明的指南,如何做到这一点。有人能请我指向正确的方向吗? Thanx

I am looking for a step-by-step how to on securing passwords put in configuration files, in grails. This means securing passwords in Config.groovy and DataSource.groovy. There are a lot of google results that contains bits and pieces of the answer, but no concise guides on how to do this. Can someone please point me in the right direction? Thanx

推荐答案

对于Config.groovy,你可以总是只是加密密码,然后把这个散列在Config.groovy,手动。当你需要在你的代码中使用它,有一些代码为你解密。似乎并不难。

For Config.groovy, you could always just encrypt the password some way and then put that hash in Config.groovy, manually. When you need to use it in your code, have some code to decrypt it for you. Doesn't seem that hard.

DataSource.groovy是一个不同的动物,但是,因为它是喂给你的Hibernate API。我确实看到一些像这样的代码在网络上,它似乎是朝着正确的方向前进...

DataSource.groovy is a different animal, however, since it is fed into the Hibernate API for you. I did see some code like this on the interwebs and it seems like it is headed in the right direction...

dataSource { 
   pooled = false 
   driverClassName = "org.hsqldb.jdbcDriver" 
   username = "sa" 
   password =  someEncryptionApiObject.decrypt(propertyFile.readProperty("MyPassword")) 
} 

...您将在其中加密包含所需数据的属性文件,

...where you would encrypt the property file containing the data you need, and decrypt when needed.

这篇关于如何加密配置文件中的密码,grails [和java]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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