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

471898
Hi,

Dont think its got anything to do with DHCP - you are connection to localhost which is always available at 127.0.0.1. I think the problem could be that I don't think the enterprise manager database console is setup to start automatically by default. On you laptop open up a command prompt and type emctl status dbconsole. Your output should be something like this:

TZ set to GB-Eire
Oracle Enterprise Manager 10g Database Control Release 10.1.0.3.0
Copyright (c) 1996, 2004 Oracle Corporation. All rights reserved.
http://tgdb01:5500/em/console/aboutApplication
Oracle Enterprise Manager 10g is not running.
------------------------------------------------------------------
Logs are generated in directory /home/oracle/product/10.1/tgdb01_TGPROD/sysman/log

If its running that is and if not you might see:

TZ set to GB-Eire
Oracle Enterprise Manager 10g Database Control Release 10.1.0.3.0
Copyright (c) 1996, 2004 Oracle Corporation. All rights reserved.
http://tgdb01:5500/em/console/aboutApplication
Oracle Enterprise Manager 10g is not running.

Try the command and post the output here....
470399
I get 'Environment variable ORACLE_SID not defined. Please define it.'.

Any suggestions?
470399
I also went to services under computer management and looked at 'oracledbconsole<dbname>', its startup type is automatic but the status column didn't have anything in it. I tried starting the service but it said there was an error, 'Microsoft could not start the service on the local computer...For more information, review the system event log...If this is a non-microsoft service, contact the service vendor with service specific error code of 2...'.
470399
I have read some of the threads about this issue and tried

set ORACLE_SID=<dbname>,

didn't get any error and then retried

emctl start dbconsole and got the following:

OC4J Configuration issue. c:\oracle\product\10.1.0\db_2/oc4j/j2ee/OC4J_DBConsol_<userid>_<dbname> not found

Any suggestions, please????
Hans Forbrich
If it does not start, there is usually a message in the event viewer log.
471898
Hi,

I have had this before a couple of times on linux and the way to fix it is to run a untility from the command prompt called emca. It will ask you what the name of your database is and the listener port is. The default listener port is 1521 by the way. Let me know how you get on....
Hans Forbrich
That's the linux way, yes. In Windows, it's the dbconsole service.

One thing the OP might want to check is the port (found in %ORACLE_HOME%\install\portlist.ini)
470399
I finally got it to work. I disabled all my network connections and then ran

set oracle_sid=<name>

and then

emctl start dbconsole.

(It would also load up immediately when I rebooted with all network connections disabled. Somehow it was trying to use the dsl/cable connection...)

Thanks for any previous responses...
Hans Forbrich
CHeck whether you have a firewall or Zone Alarm. Seems that tends to block accesses.
1 - 9
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,635 views