0

I have been reading various articles online about how best to store passwords for this sort of purpose. So far the closest I have is by adding the password to a keystore file created through the command prompt. With this approach all I can do is access the SecretKey object

SecretKeyEntry entry = (KeyStore.SecretKeyEntry)ks.getEntry("vault",new KeyStore.PasswordProtection(password));
            SecretKey someKey = entry.getSecretKey();
            System.out.println(someKey.getEncoded());

This works but to access the SecretKeyEntry I have to pass the password of the keystore in as a plaintext string and call the toCharArray method. Also from this then how could I actually go about using the value to connect to MySQL.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
deco
  • 137
  • 2
  • 11
  • Possible duplicate of [Encrypt Password in Configuration Files?](http://stackoverflow.com/q/1132567/5221149) – Andreas Mar 24 '17 at 23:48
  • 2
    There has to be a cleartext password _somewhere_ if your Java program is to start up without manual intervention. If you can't do that then you'll have to have someone manually enter the password at startup, which just pushes the problem somewhere else (who has access to the password list). If you encrypt the password in the configuration you'll need to store the encryption key somewhere, and it will need to be password protected, so it's "turtles all the way down". – Jim Garrison Mar 25 '17 at 00:56
  • Thanks @JimGarrison With saving the password in configuration or a properties file or any of those methods. Is there any method to use the encrypted value to connect to mysql workbench? – deco Mar 25 '17 at 19:23

1 Answers1

0

If you are deploying your application to an application server (Weblogic/tomcat) you can create a datasource on the server with the required credentials to the database. From your application you can connect through the datasource just by mentioning its name.

Elio Khattar
  • 320
  • 1
  • 3
  • 16