Java Play Encrypt Database Password

大憨熊 提交于 2019-12-02 17:32:37

问题


I'm developing a Java Play application and I'm storing the Database password in plain text inside the application.conf file.

db.default.url="jdbc:oracle:thin:@HOST:PORT/SID"
db.default.user=USER
db.default.pass=PW

Now i want to store it as an encrypted password.

While searching for a solution I saw many articals about implementing a plugin. Following is an solution I came across.

Encrypting db password in application.conf

In that example, play.PlayPlugin is used but when I try it, I get an package not found error. Do I need to insert an external jar file or is it because of a version problem. I'm using Java play 1.2

Is there any other way to store password in encrypted format other than a plugin.


回答1:


You shouldn't need to encrypt anything inside your own system. Just make sure your server is secure.

Since you will need to let your application access the password, an attacker who has access to your system would be able to get to your password anyway.

But never ever check your passwords into git (or subversion or whatever)!

Instead what you should do is this:

  1. Add this line to your application.conf:

    include "secure.conf"
    
  2. Create the secure.conf in your conf-folder.And save all your credentials in this file.

  3. Add secure.conf to your .gitignore, so it doesn't go into your Git.
  4. Manually add and update the secure.conf-file on your server.



回答2:


Is there any other way to store password in encrypted format other than a plugin.

Well you could create your own formula for encrypting and decrypting the password. For example you can store the password in character array, make characters into bytes, do something to those bytes and save it into a file. For decrypting you just do all that stuff backwards.



来源:https://stackoverflow.com/questions/32092701/java-play-encrypt-database-password

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!