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!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Getting a java.security.InvalidAlgorithmParameterException: Wrong IV length

843810Jan 30 2004 — edited Feb 2 2004
Hello,
I am trying to encrypt a string within the same class. I am using the same key for both encrypting and decrypting. Not being familiar with JCE I am not sure what the exception here means -

java.security.InvalidAlgorithmParameterException: Wrong IV length: must be 8 bytes long. I am using JDK 1.4.2.

Here is the code for encrypting and decrypting(its adapted from the Scott Oaks book) -

private AToken getSOAPAuthToken(String p_userName) throws Exception
{
KeyGenerator kg = KeyGenerator.getInstance("DES");
Cipher c = Cipher.getInstance("DES/CBC/PKCS5Padding");
Key key = kg.generateKey();
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("keyFile"));
oos.writeObject(key);
c.init(Cipher.ENCRYPT_MODE,key);
byte input[] = p_userName.getBytes();
byte encrypted[] = c.doFinal(input);
String userToken = new sun.misc.BASE64Encoder().encode(input);
String userVector = new sun.misc.BASE64Encoder().encode(encrypted);
AToken sat = new AToken(userToken,userVector);
return aToken;
}
private void decryptToken(AToken p_sat) throws Exception
{
Cipher c = Cipher.getInstance("DES/CBC/PKCS5Padding");
ObjectInputStream ois = new ObjectInputStream(new FileInputStream("keyFile"));
Key key = (Key)ois.readObject();
String userVector = p_sat.getUserToken();
byte iv[] = new sun.misc.BASE64Decoder().decodeBuffer(userVector);
IvParameterSpec dps = new IvParameterSpec(iv);
c.init(Cipher.DECRYPT_MODE, key,dps);
byte encrypted[] = new sun.misc.BASE64Decoder().decodeBuffer(p_sat.getUserToken());
byte output[] = c.doFinal(encrypted);
s_logger.info("The value of output is " + new String(output));
}

Comments

843833
Hi,

Can you explain what you have changed, or even better, can you post both the unmodified and the modified wsdl. Furtermore, have you saved the document with the right encoding. With wordpad, I am always afraid it changed the encoding. You'd better use notepad or better Textpad or a similar text editor.

Martijn
843833
it is a clasloading problem. axis2 use wsdl4j-1.5.1.jar, change to wsdl4j-1.6.x.jar should solve the problem
PhHein
Welcome to the forum. Please don't post in threads that are long dead and don't hijack other threads. When you have a question, start your own topic. Feel free to provide a link to an old post that may be relevant to your problem.

I'm locking this thread now.
1 - 3
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Mar 1 2004
Added on Jan 30 2004
1 comment
1,628 views