Hi,
I need to store usernames and passwords for database connections in my database. I can't use a hash to encrypt these as I need to get the original values back to include them in the connection string.
I'm looking at using the Cipher class to do this, but am struggling. I've taken the following steps so far:
- used keytool -keygen to generate a keystore with a key
- used keytool -selfcert to create a certificate
All good so far. Here's my code to try to init the Cripto object:
javax.crypto.Cipher c = Cipher.getInstance("DES/CBC/PKCS5Padding");
KeyStore store = KeyStore.getInstance("jks");
store.load(new FileInputStream(new File("./res/cert/pres.keystore")),
new char [] {....});
X509Certificate cert = (X509Certificate) store.getCertificate("presence");
cert.checkValidity();
c.init(Cipher.ENCRYPT_MODE, cert);
This bombs out when I try to call c.init, with this exception:
java.security.InvalidKeyException: Invalid key length: 443 bytes
at com.sun.crypto.provider.DESCipher.engineGetKeySize(DashoA6275)
at javax.crypto.Cipher.init(DashoA6275)
at javax.crypto.Cipher.init(DashoA6275)
at com.internationalpresence.dataobjects.User.main(User.java:293)
Any suggestions as to where I'm going wrong?
Help is very much appreciated - thanks in advance
Matt