Work from command line but did not work from JSP call

I have a test class that should perform Triple DES. When I run it from command line work ok, but when runs from JSP it give me an error:
Exception:
======================================
javax.crypto.IllegalBlockSizeException: Input length not multiple of 8 bytes
put 3 check points inside the code, and run it from command line and here is the result:
C:\Documents and Settings\salasadi\Desktop\DigitalMailer>java TDESStringEncrypto
r 123456781234567812345678 "CID=103&A
this is pass 3
this is pass 1
this is pass 2
here is the class:
import javax.crypto.*;
import javax.crypto.spec.*;
import java.security.*;
import java.io.*;
public class TDESStringEncryptor
static final int DATA_STRING_LENGTH = 64;
public static void main(String[] args)
try
TDESStringEncryptor enc = new TDESStringEncryptor();
String value = enc.Encrypt(args[0], args[1]);
System.err.println(value);
catch (Exception ex)
System.err.println(ex);
public String Encrypt(String inkey, String data)
throws Exception
// convert key to byte array and get it into a key object
byte[] rawkey = inkey.getBytes();
DESedeKeySpec keyspec = new DESedeKeySpec(rawkey);
SecretKeyFactory keyfactory = SecretKeyFactory.getInstance("DESede");
SecretKey key = keyfactory.generateSecret(keyspec);
Cipher cipher = Cipher.getInstance("DESede/ECB/NoPadding");
cipher.init(Cipher.ENCRYPT_MODE, key);
byte[] out = cipher.doFinal( padString(data).getBytes( ) );
System.out.println("this is pass 1");
return byteArrayToHexString( out );
private String byteArrayToHexString(byte in[])
byte ch = 0x00;
int i = 0;
if ( in == null || in.length <= 0 )
return null;
String pseudo[] = {"0", "1", "2", "3", "4", "5", "6", "7", "8",
"9", "A", "B", "C", "D", "E", "F"};
StringBuffer out = new StringBuffer( in.length * 2 );
while ( i < in.length )
ch = (byte) ( in[i] & 0xF0 );
ch = (byte) ( ch >>> 4 );
ch = (byte) ( ch & 0x0F );
out.append( pseudo[ (int) ch] );
ch = (byte) ( in[i] & 0x0F );
out.append( pseudo[ (int) ch] );
i++;
String rslt = new String( out );
System.out.println("this is pass 2");
return rslt;
private String padString( String s )
StringBuffer str = new StringBuffer( s );
int strLength = str.length();
for ( int i = 0; i <= DATA_STRING_LENGTH ; i ++ )
if ( i > strLength ) str.append( ' ' );
System.out.println("this is pass 3");
return str.toString();
And here is the JSP call:
TDESStringEncryptor encryptz = new TDESStringEncryptor();
String cryptodata1 = encryptz.Encrypt(Keyz,cryptodata);
Thanks

Please use [ code ] tags when posting code.
Please indicate the line that causes the exception.
Please indicate what Keyz and cryptodata is.

Similar Messages

  • Query runs from command line, but not from scheduler

    We use Control-M to schedule shell scripts to be run on a Solaris server. Some of the scripts have to access an Oracle database and in that case our security team will include the DB user and password in the script, then encrypt it and the sys admin team schedules the encrypted shell script with Control-M. That works fine, but we've been trying to have the DB user and password on a separate encrypted file so that we don't have to ask for file encryption every time it's necessary to modify a script (this is a test environment).
    We have the script at ~/system_name/scripts, the query at ~/system_name/sql and the encrypted file and key at ~/system_name/keys. The SQLPlus call in the script is:
    ${ORACLE_HOME}/bin/sqlplus "`decrypt -a 3des -k ./../keys/key.3des.system -i ./../keys/login.system`"@instance_name <<EOF
    @${DIR_SQL}/TEST_QUERY.SQL
    quit
    EOF
    The security analyst has tested is successfully from command line, but when we schedule it with Control-M the job abends and we get the following in the sysout:
    + decrypt -a 3des -k ./../keys/key.3des.system -i ./../keys/login.system
    decrypt: cannot open ./../keys/key.3des.system
    decrypt: invalid key.
    + /u00/app/oracle/product/11.1.0/db_1/bin/sqlplus @instance_name
    + 0<<
    @/sistemas/hmp/system_name/sql/TEST_QUERY.SQL
    quit
    SQL*Plus: Release 11.1.0.6.0 - Production on Mon May 3 09:41:55 2010
    Copyright (c) 1982, 2007, Oracle. All rights reserved.
    SP2-0310: unable to open file "instance_name.sql"
    Enter user-name: SP2-0306: Invalid option.
    Usage: CONN[ECT] [logon] [AS {SYSDBA|SYSOPER|SYSASM}]
    where <logon> ::= <username>[<password>][@<connect_identifier>] [edition=valu\
    e] | /
    SP2-0306: Invalid option.
    Usage: CONN[ECT] [logon] [AS {SYSDBA|SYSOPER|SYSASM}]
    where <logon> ::= <username>[<password>][@<connect_identifier>] [edition=valu\
    e] | /
    Enter password:
    ERROR:
    ORA-12545: Connect failed because target host or object does not exist
    SP2-0157: unable to CONNECT to ORACLE after 3 attempts, exiting SQL*Plus
    0000000080
    Any ideas?

    Looks like the command is being split in some way - the connection to sqlplus is being made before it completes the whole string
    It appears to be seeing the @instance_name as a script to execute rather than a db to connect to.
    Is the database on the same server as the script?
    If so, try setting your environment to the correct databsae, so that you can omit the @instance_name part of the syntax and see if it helps
    Also just noticed the failure to open the decrypt script. It would appear uyou are not using a full path name. Have you checked which directroy the scheduled job starts in? You may need to look at running some environment specific scripts first.
    Edited by: LindaA on 05-May-2010 07:43

  • What to do now when my iPad won't turn on after I turn it off. It shows only the apple logo. I am sure it has above 70% charge as when I sync my iPad it shows necessary detail in iTunes. I have tried, HOME & POWER button, but did not work.

    What to do now when my iPad won't turn on after I turn it off. It shows only the apple logo. I am sure it has above 70% charge as when I sync my iPad it shows necessary detail in iTunes. I have tried, HOME & POWER button, but did not work.

    First try a Reset  ( No Data will be Lost )
    Press and hold the Sleep/Wake button and the Home button at the same time for at least Ten seconds... (But can take Longer)... until the Apple logo appears. Release the Buttons
    If no joy... Try a Restore...
    1: Connect the device to Your computer and open iTunes.
    2: If the device appears in iTunes, select and click Restore on the Summary pane.
    Restoring  >  http://support.apple.com/kb/HT1414
    Make sure you have the Current Version of iTunes Installed on your computer
    iTunes free download from www.itunes.com/download
    3: If Unable to Restore, try using the Steps in this article to force the device into Recovery Mode.
    Note on Recovery Mode.
    You may need to try this More than Once... Be sure to Follow ALL the Steps...
    After you have Recovered your Device...
    Re-Sync your Content or Restore from the most Recent Backup...
    Restore from Backup  >  http://support.apple.com/kb/ht1766

  • HT201401 Hi.. My Iphone acts as if it is dead. Tried a lot with Sleep +home buttons as well, but did not worked. When it is plugged in, keeps on charging with a regular beep. Please advise.

    Hi.. My Iphone acts as if it is dead. Tried a lot with Sleep +home buttons as well, but did not worked. When it is plugged in, keeps on charging with a regular beep. Please advise.

    Yes, I understand that. But The screen issue is not a result of user damage. The phone was not dropped when the screen got cracked. My daughter was standing in a chair at the table and dropped one of her toys onto the bottom of the phone and cracked it right by the home button. (Nowhere near the LCD/digitizer flex cables, connections, or logic board components) then a few months later my phone had died, I plugged it in, it showed it was charging, then Apple logo disappeared and screen didn't work. AFTER contacting Apple about the issue and them telling me that it "is a result of the very minimal crack to the sheet of glass that has no relation to the LCD or Digitizer and that the warranty does not cover it I had taken it upon myself to change the LCD/digitizer to no avail, as well as backlight ic and backlight coil to no avail. But how do I go about letting Apple know that it is in fact NOT due to the cracked screen nor is it due to the flex cable connections? I can't. So the lady that works the call center phones  trying to "convince" me that she knows what she is talking about and "convince" me that it is from the cracked screen I have to take her word because I can't show Apple that its not because of that without paying them $199 to fix the screen in which case they will just send me a new phone rather than fix the faulty hardware under warranty.

  • HT5654 Just tried 3 times to update iTunes on my PC running Vista.  There was an error.  It stopped the installation.  Now iTunes will not start at all.  The error message tells me to reinstall which I tried but did not work.  What should I do?

    Just tried 3 times to update iTunes on my PC running Vista.  There was an error.  It stopped the installation.  Now iTunes will not start at all.  The error message tells me to reinstall which I tried but did not work.  What should I do?

    Hello, Jdragone. 
    Thanks for the question.  Start with completely uninstalling iTunes and all of it's components in the order specified in the article below.  Once this is done, download and install iTunes.
    Removing and reinstalling iTunes and other software components for Windows Vista, Windows 7, or Windows 8
    http://support.apple.com/kb/HT1923
    If you receive any errors when uninstalling any components of iTunes, try the steps in the article below for each component that gives you an error.
    "The feature you are trying to use is on a network resource that is unavailable" alert appears when removing Apple software in Windows
    http://support.apple.com/kb/TS3704
    Cheers,
    Jason H.

  • When i go in my settings on my ipod touch 3gen it says no wi-fi as in i cant connect to any wi-fi at all i tried to restore but did not work HELP PLEASE

    when i go in my settings on my ipod touch 3gen it says no wi-fi as in i cant connect to any wi-fi at all i tried to restore but did not work HELP PLEASE

    See:
    iOS: Wi-Fi or Bluetooth settings grayed out or dim
    If not successful, an appointment at the Genius Bar of an Apple store is usually in order.
    Apple Retail Store - Genius Bar

  • I sign in tol my Firefox is out of date. did try to do the upgrade but did not work need help

    ''locking this thread as duplicate, please continue at [https://support.mozilla.org/en-US/questions/978554 /questions/978554]''
    I need help to get my sign in working. Need to upgrade?
    how to do that?
    <sub>edit: removed personal information for your protection. (philipp)</sub>

    I sign in told my Firefox is out of date. did try to do the upgrade but did not work. Need help
    Let me know how to get my sign in working

  • Appletv 2 flashing quickly - no reponse at all -tried to unplug power but did not work.

    Appletv 2 flashing quickly - no reponse at all -tried to unplug power but did not work. What should i do?

    You'll have to connect the your ATV2 to computer via micro-usb port on the back. Open itunes and put the ATV2 in DFU mode by holding down the menu and play button for 7 seconds. Itunes should recognize the device. Once it does press the restore button,itunes will then download the latest software and reinstall it on the ATV2.  You will then have to go through the setup process again. If that doesn't fix the problem take it back the store you bought it at.

  • I need my redemption code. Followed all tips, but did not work. Had to reinstall Windows 8Redemption Code - forgot mine

    I need my redemption code. Followed all tips, but did not work. Had to reinstall Windows 8 due to Windows Explorer crash issue,and had to reinstall all softwares. I am a monthly regular CC customer, and dont recall my 24 digit  code.

    Since this is an open forum, not Adobe support... you need to contact Adobe staff to help
    Adobe contact information - http://helpx.adobe.com/contact.html
    -Select your product and what you need help with
    -Click on the blue box "Still need help? Contact us"
    -or by telephone http://helpx.adobe.com/x-productkb/global/phone-support-orders.html

  • My appstore n camera icon has gone..anyone can help me..i already try to go setting and restriction but did not works..

    My appstore n camera icon has gone..anyone can help me..i already try to go setting and restriction but did not works..
    I also cannot update ios..how to solve this problem..?

    Your going to have to perform a restore.

  • My outgoing mail server smtp remains offline. I have tried using different port but did not work. What else can I try?

    My outgoing mail server smtp remains offline. I have tried using different port but did not work. What else can I try?

    OS X Mail: Troubleshooting sending and receiving email messages

  • TS4036 I have moved from one company to another and they both use iphones I backed my phone up before it was shut down I tried to retrieve contacts from my PC it did not work will it work when I get my new iphone?

    I have moved from one company to another and they both use iphones I backed my phone up before it was shut down I tried to retrieve contacts from my PC it did not work will it work when I get my new iphone?

    I updated my iPhone onto my friend's MacBook
    Why would you do that, and not on your own computer?  See the hassle it caused you?
    can he just email me the folder
    Backup files are too big to email.  Use FTP, DropBox, etc...
    how do I then put all that data back into my current phone from the new computer?
    How to restore iPhone:  http://lmgtfy.com/?q=how+to+restore+iphone

  • HT4236 I've been using the iCloud Photo Stream with my PC for few months already. It work fine every time, but suddenly not work for today

    I've been using the iCloud Photo Stream with my PC for few months already. It work fine every time, but suddenly not work for today

    Hey lalitgupta,
    Thanks for the question. The following article provides troubleshooting steps for Photo Stream:
    iCloud: Photo Stream troubleshooting
    http://support.apple.com/kb/TS3989
    Thanks,
    Matt M.

  • Reading message from MQ- works in WSAD (IDE) but does not work outside WSAD

    Read from MQ:
    Same code works within WASD but does not work outside WSAD.

    PDL - thanks for the suggestions - here are the results:
    A button on the form that executes "this.print();" works fine.
    Changing "this" to "event.target" results in the same error.
    document.getElementById("PDFObj").Print(); works fine.
    However, the reason that I'm using ".postMessage([message])" instead of ".Print()" is because I actually have a toolbar that has save, print, zoom in, zoom out, page up, page down, etc.... I simplified the switch statement in the post above to only include print, but in reality has a case for each of the functions above. The postMessage call is triggering the error, since the catch statement is printing out the error message above. Any idea why this would work with Professional but not Reader.

  • Can not get web page all of the way out to edge of computer screen tried to drag but did not work

    just got a new computer ..when i go to a web page the page does not go all of the way out to the side of the screen...i tried to grab and drag it but it did not work...i am new to this computer thing...need help

    I just had that problem today and although it unfortunately probably won't help you minus47, (as you said disabling your Add-ons didn't help) I tracked my problem down to 'Fierr' as the culprit and disabling it fixed it.
    To be honest I don't know why as 'Fierr' hasn't been updated since January '11 and Firefox only started playing up today.
    The only other thing I updated today was Flash Player but I'm not sure if I installed it before it started playing up though.
    Hopefully this might help someone else.

Maybe you are looking for

  • "broken assets" error message when saving project as disc image

    I've seen this question asked before but I've been unable to find a solution that works. I am using iDvd6. After creating my project in iMovie, I shared it with iDvd. I then added a slide show and some music. Before burning to disc I "save as disc im

  • Strange looking PDF email attachments

    Hi, We are sending out a lot of output documents (like order confirmations, invoices, etc) from our 4.6B R/3 system to our customers as a PDF file attached to an email. For now, we are only using normal SapScript. Recently we got complaints from (for

  • CPU utilization problem with JSF

    Hi, I am using MyFaces 1.1.4 and tomahawk 1.1.3. I am using EJB 2.0 and weblogic server 9.2 I have a problem with the performance of my application. The response time for 500 concurrent users is arnd 10sec. However, the CPU utilization normally hits

  • Storage in ODS

    Hi I would like to know how the data is being stored in ODS. Will it store all the versions of delta or will it be having single latest record always. Please let me know. Regards Leon

  • I cant view my videos

    I downloaded a few podcast videos and purchased one as well, I can view them on my computer but I cannot view them on my ipod. If someone could help me out and give me direction I would appriciate it:) Thanks