Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Problems with Cipher

843810Jun 25 2003 — edited Feb 1 2006
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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 1 2006
Added on Jun 25 2003
7 comments
582 views