Why the Decrypted message disordered

THAT IS MY ASSIGNMENT WORKS
(a) Write the program GenKey so that when the following statement is executed:
java GenKey abc1234 c:\key.dat
java Encrypt c:\key.dat c:\inputfile.dat c:\outputfile.dat
java Decrypt c:\key.dat c:\inputfile.dat c:\outputfile.dat
Then, a DES key will be read from the location c:\key.dat and the input file at c:\inputfile.dat will be read and decrypted using the DES command. The output will be written to the file at c:\outputfile.dat.
The result and code as follows, I don't know why totally! When I use FileOutputStream, decrypted unsucessful due to pedding mismatch, BUT USING DataInputput/OutputSream, the result as follows.
Original code
Hong Kong Welcomes You
Encypted message
Ðý?$šg?„rêg’ú?ÿ?7ºþnss �æ‚i+
Decypted file
es YouHong Kong Welcomes
Edited by: Jeckys_Rocket on May 6, 2008 7:09 AM
import java.io.*;*
*import java.security.*;
import javax.crypto.*;*
*public class Encrypt {*
*private Cipher encryptCipher = null;*
*private Cipher decryptCipher = null;*
*public Encrypt(String args []) {*
*javax.crypto.SecretKey key=null;*
*try {*
*// byte[] re=cipher.doFinal(this.message.getText().getBytes());*
*ObjectInputStream input=new ObjectInputStream(new FileInputStream(args [0]));*
*key=(SecretKey)input.readObject();*
*encryptCipher = Cipher.getInstance("DES");*
*encryptCipher.init(Cipher.ENCRYPT_MODE, key);*
*decryptCipher = Cipher.getInstance("DES");*
*decryptCipher.init(Cipher.DECRYPT_MODE, key);*
*DataOutputStream dataOutputStream = new DataOutputStream (new FileOutputStream(new File(args[2])));*
*DataInputStream dataInputStream = new DataInputStream( new FileInputStream(args[1]));*
*DataInputStream dataInputStreamt = new DataInputStream( new FileInputStream(args[1]));*
*int cout=0;*
*byte [] bc=null;*
*String temp="";*
*String name="";*
*try{*
*// for(int i=0;i<10;i++){*
*for(;(dataInputStreamt.read())!=-1;){*
*cout++;*
*bc=new byte [cout];*
*int temps=dataInputStream.read(bc);*
*// if(temp==null)*
*// {break;}*
*// name=name+temp;*
*}catch(IOException e){*
*e.printStackTrace();*
*//String name=temp;*
*name =new String(bc);*
*name=new String(bc);*
*System.out.println("see "+name+""+bc.length);*
*//name=temp;*
*FileOutputStream dos = new FileOutputStream(new File(args[2]));*
*// int rs=0;*
*// byte [] b=new byte [1000];*
*// rs=0;*
*/* for (int i=0;(rs = dis.read()) != -1;i++)
b=(byte)rs;
*// for(int i=0;i<b[i];i++){*
*// b[i]=b[i];}*
*// String strp=new String(b);*
System.out.println("plain "+ name+" end plain");
byte [] encypted=encryptCipher.update(name.getBytes());
encypted=encryptCipher.doFinal(name.getBytes());
String strp=new String(encypted);
System.out.println("EN "+ strp);
byte [] de= decryptCipher.doFinal(strp.getBytes());
String str1="";
str1=new String(de);
System.out.println("decypted "+str1);
dos.write(strp.getBytes());
dataOutputStream.write(strp.getBytes());
*/* if (dis != null) dis.close();
if (dos != null) dos.close();*/
catch (Exception e) {
e.printStackTrace();
System.out.println("File not found: " + args[0]);
public static void main(String [] args){
Encrypt e=new Encrypt(args);
WHAT IS WRONG?
Edited by: Jeckys_Rocket on May 6, 2008 7:18 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

There is so much wrong that I won't detail the problems. To encrypt you should be following
1) Open the source file with a FileInputStream.
2) Open the output file with a FileOutputStream.
3) Wrap the FileOutputStream with a CipherOutputStream constructed with the FileOutputStream and your Cipher initialized to 'encrypt' mode.
4) Loop reading a buffer of data from the FileOutputStream and write it to the CipherOutputStream until you reach the EOF of the FileInputStream.
5) Close the CipherOutputStream (NOT NOT NOT the FileOutputStream).
6) Close the FileInputStream.
To decrypt one uses the same basic approach in reverse.
P.S. There is no point in trying to print out the encrypted file since it contains binary data and not characters.
Edited by: sabre150 on May 6, 2008 4:07 PM

Similar Messages

  • SUP 2.0 Why the sybase Messageing Service doesn't start?

    Hellow experts,
    SUP 2.0 Why the sybase Messageing Service doesn't start?
    When I start the service, it starts and ends indicating "if they are not in use by other services or programs; it will end automatically"
    What should I do for this?
    Thanks
    Prabakar

    sometimes you only have to restart your pc. STOP SUP SERVICE ( AS ADMINISTRATOR ) and START SERVICE ( AS ADMINISTRATOR AGAIN ) ...
    That happens to me very often!

  • Why the error message?

    Do I really have to get an error message every time I start iTunes but I'm not connected to the internet? I mean the one that says "Uh-oh, we couldn't connect to the Store!" Is there any way to supppress that?
    iBook G4   Mac OS X (10.4.8)   768 MG RAM

    Yes there is. Go to iTunes>Preferences>Store and uncheck "Automatically download pre-purchased content". That should do it. Good luck.

  • Cannot import pictures from Nikon D90.  Computer says all are unreadible.  Already successfully imported to Aple laptop.  Why the 'unreadible' message.

    Trying to import photos from Nikon D90 camera.  Computer saying all files are unreadible.  Impossible!!! Just imported to laptop.  Anyone know what would cause this message. 

    I've tried IPhoto and Nikon View.  IPhoto does nothing and Nikon View says files unreadible.

  • How to resolve the error message "JBO-25009" in ADF table?

    Hi all,
    There is a master detail form in jsff page using adf application. Detail is represented as ADF table. In the adf Table we have 4 primary key, two foreign key from master table.
    Type of primary key in master are Big Decimal and String. When I input value in field of detail, we get error message :
    "JBO-25009: Cannot create an object of type:java.math.BigDecimal from type:java.lang.String with value:AC".
    How to make if I input value in detail table don't show the error message?
    Please let me know if you have any solution for this.
    Thanks.

    Hi Rakesh.
    I don't try insert String into Big Decimal variable. I have adf table with 5 column and 4 primary key. The type of primary key are: 1Big Decimal and 3 String.
    Now, I want to insert data to the table. when I input data to first column (primary key : Big Decimal) is work well and then I want to insert data to second column (primary key : String) with value "AC"
    but when I insert, the error message is show "JBO-25009: Cannot create an object of type:java.math.BigDecimal from type:java.lang.String with value:AC".
    Why the error message is show when I insert data to second column with type String and I have been input data with String value?
    Are the second column is remember of type first column is Big Decimal ?
    Thanks.

  • In iCal - I keep getting the error message " This calendar was created by Mail" and it will not accept any input; why..??

    In iCal - I keep getting the error message “ This calendar was created by Mail” and it will not accept any input; why..??

    use Disk Utility and Verify Permisions then fix and Verify Disk and fix, this should fix it.

  • Why can't i add playlists to my iPhone from my mac while they are connected? I keep getting the following message "some items (meaning all of them) were not transferred because iTunes match is enabled." This is incredibly frustrating.

    I keep getting the following message "some items (meaning all of them) were not transferred because iTunes match is enabled." when I try to drag and drop a playlist, song, or album to my iPhone. This was NEVER a problem before iTunes match or the last iOS update. So what is the deal? Why can't i just add music to my phone from the mac? There is space on the phone. The only way I have found to get the music i want to the phone is to have it download from the phone. This is not something i want to have to do: go through and manually add every album and recreate a playlist on the phone when its there on the mac. And, even more irritating, since the new update, when the phone is plugged into the mac i can't actually view from the mac what music is on the phone. This is incredibly frustrating and any help would be much appreciated in managing my music libraries for each device.

    Hi,
    You cannot manually manage music with match turned on on your iOS device. If you want to manage music manually, you will need to turn off match on your iPhone.
    Jim

  • I'm trying to update my iphone 3GS to the 4.3.4 version and I am getting the error message "This version of itunes (version 9.1.1) is the current version.  How do I update my PHONE and why is an itunes update being confused for my iphone?

    I'm trying to update my iphone 3GS to the 4.3.4 version and I am getting the error message "This version of itunes (version 9.1.1) is the current version.  How do I update my PHONE and why is an itunes update being confused for my iphone?

    You need iTunes 10.0 or greater to update your phone...iTunes isn't confused at all. If you're on a Mac, you'll need OS X 10.5.8 or greater to update iTunes to 10.0 or greater.

  • Why do I get the error message "unable to load page (HTTP 502) when I try to open Mobile Web?

    I have an LG Octane 3 basic phone.   Does everything I need, phone and text, and I never was interested in web or e-mail capabilities until I recently upgraded our plan to the "More Everything" and was able to use data and check e-mail and access the internet.   Whenever I try to open Mobile Web, I get the error message "unable to load page (HTTP 502)".    As of March 31, 2015, all of us basic phone users lose the "Mobile Email" app on our phones, and will have to access web versions of our e-mail via the web.  Which is currently unavailable and doesn't work.
    Over a week ago, did a chat session with a tech support rep, and she indicated that either she or an engineer would contact me with how to fix the problem.   Have not heard anything from anybody, and the deadline is approaching quickly.   Have no need of all the excess features of a smart phone, nor do I wish to be forced to jettison a perfectly working phone for my needs and buy something I don't want to be able to do 2 simple things.............check e-mail to see if there's something that needs to be answered right away, and to check traffic reports when I'm on the road, or find something in an area with which I'm not familiar.     Not really too much to ask, you would think....   )
    Has anyone else had this same problem, and if so, how do we fix it....???  My next move is a phone call, but those haven't always been very productive.
    If any of you have any ideas why this error keeps coming up and the web can't load, and some on how to fix it, I would really appreciate some advice.
    Thanks in advance.
    Karen

    Since the chat session got no reply, I contacted Verizon by phone and a very nice level 2 tech created a trouble ticket and sent it up the food chain.  Got a call back, maybe 2 days later, and had a nice, although very long session with a higher level tech.  They had determined that the browser for the LG Octane is an old one and no longer supported by Verizon.    We tried everything we could to download the Opera browser, but since I was totally unable to get Mobile Web to work, couldn't do it.   The only other possible "fix" was to totally reset the phone to factory specs and try it again.   That would mean a lot of work on my part to move anything I didn't want to disappear off the phone, and find a place to forward texts that had to be saved.   Caught our tenants lying about why the rent was late (again), and need that for when I put them back on a lease....  
    Long story short is that unless we try this total reset, which isn't a sure fix, either, anyone who isn't able to access the Mobile Web with the LG Octane will have to change their plan to avoid paying for data that you can't access using any method. 
    I ran a test with an app that I knew was no longer valid.....that was sending photos to PixPlace.   Got the exact same error message as when trying to access Mobile Web to get the web version of my e-mail.   That just verified that the 502 error is, at least in the LG Octane, for an app that no longer works.   After today, we'll get the same thing when we try to access Mobile E-Mail.
    Have to admit, it's a real ****-off, but this shouldn't surprise me, since Verizon won't repair older copper phone lines if you are in an area where FIOS is offered. 
    I am going to immediately change my husband's and my cell phone plan to one without data, and see what I can find that will still give unlimited calls and text.  The way my luck runs, they won't offer one for a decent price.  The other half has some very long-winded friends and he was always running over minutes, and some months are very text-heavy and I'd go over my limit.   Absolutely HATE touch screens, and am not looking forward to having to get a new phone.  

  • Why does the error message "Microsoft Outlook must be closed because an error occurred" keep coming up?

    why does the error message "Microsoft Outlook must be closed because an error occurred" keep coming up?

    Reboot the machine.

  • My ipod 60gb classic is showing as fully charged until I connect it to my pc when it comes up with the error message, 'please wait very low battery' and the little wheel goes round and nothing happens, can anyone explain why this is and what i can do?

    My ipod 60gb classic is showing as fully charged until I connect it to my pc when it comes up with the error message, 'please wait very low battery' and the little wheel goes round and nothing happens, can anyone explain why this is and what i can do?

    I have worked my way through the assistant and nothing works. I have tried connecting in disc mode but although the screen on the ipod is showing that the device is charged and that it is in disc mode as soon as I connect it to the computer it comes up with the error message 'please wait very low battery' and stays like that until I disconnect when it appears to be OK again. I have tried on both pc and mac.
    BTW the ipod is an ipod video not classic if that makes any difference.
    Thanks

  • Why am I receiving the "Unfortunately, Messaging has stopped" error message and how do I fix it?

    Why am I receiving the "Unfortunately, Messaging has stopped" error message and how do I fix it?

    I am so upset. Please read my messages from my postings. This has nothing to do with SIM Card, Hard Reset, Apps, Google Gmail Account, nothing. I have gone thru all of this and NOTHING has fixed this. I went to the store today and spoke to the manager on duty. He said he had to try and duplicate the problem before he could help me. I showed him "screen captures" I did, told him it's out here on the board, etc. etc. Needless to say I ended up coming home with the same phone, "he" erased the phone and started over again. Well guess what, it's not a error with "MY" Gmail account being corrupted because if that is the case Mrs. Hayden14 has a bad Gmail account too. If you guessed it, the phone just crashed again! I was able this time to capture a report with ALL the history in it and saved screen captures to PROVE to him this is not a joke. Even the report says "Crash". This time it was something else I don't even or ever have used. I have also wasted over a day , yes a full work day on this without question.
    I have had to get the run around for the last day. This is totally ridiculous, including them putting me on hold for 55 min. Oh, that's another funny story. Anyways, tomorrow morning I am going to the Verizon store one last and final time and I hope they decided to do the right thing and give me a phone that does not crash and works. It would be handy at work for me, especially where I work at. I hope hope hope someone listens to and helps me. I would love for them to see me walk in, take my phone and say to me were going to get you another phone, hand it to me, see if it works and prove it's the device. I don't hear anyone having this issue on other phone types so sounds like its the phone type.
    I have had 3 phones now in the matter of 2 weeks. I am sure the FedEx charges will add up to a cost of a new phone at some point and start to outbalance your requirement to give me the same phone when it has the same problem.
    Can't wait to see what happens tomorrow.

  • I have 2 phones on my iTunes account, why are text messages showing on the second phone when sent from the first

    I have 2 phones on my iTunes account, why are text messages showing on the second phone when sent from the first phone?

    it's meant to work like that
    so if you receive a message on your iphone you also get it on your ipad or ipod touch
    to avoid it use separate appleID for each device
    or turn off imessage on 1 or both devices in their settings
    but that will not fix the issue that 2 devices using the same appleID will never be able to facetime eachother
    the appleID is a unique handle for 1 user only

  • Why do i get the following message when i attempt to open my backup file for lightroom cc?  "Lightroom cannot use the catalog named "Lightroom Catalog" because it is not writable and cannot be opened".  This message just started coming  up after downloadi

    why do i get the following message when i attempt to open my backup file for lightroom cc?  "Lightroom cannot use the catalog named "Lightroom Catalog" because it is not writable and cannot be opened".  This message just started coming  up after downloading lightroom cc (previously using lightroom 5)...am i backing up properly or not???

    Open Pictures folder and move the files named lrcat-journal and lrcat.lock to Desktop.
    Make sure that , they are not inside Pictures folder any more and try to open backup from Lighrtroom and check..
    Any LRcat file with .lock extension , move it to Desktop.

  • I have just clicked on my iTunes desktop icon and got the following message "The file iTunes Library.itl" cannot be read because it was created by a newer version of iTunes. Why has this occurred when it working fine?

    I have just clicked on my iTunes desktop icon and got the following message "The file iTunes Library.itl" cannot be read because it was created by a newer version of iTunes. Why has this occurred when it working fine? Is it best to update iTunes to 10.2 to attempt to resolve? Initially I got the prompt Quicktime was out of date so I updated that successfully in all programs. I do not want to lose my iTunes library.

    Sorted problem updated and reinsatlled and restarted computer.

Maybe you are looking for

  • After using the cable to charge my iPad I can't sync my iPod touch

    I just got the iPad 2 and I have been using my old USB cable to charge it on my laptop and on the adapter it came with. Now when I use the USB cable to connect my iPod touch to my laptop to sync, it doesn't show up in the devices column. I don't know

  • Reset Usage Decision and reverse posting in tcode QA12

    Hi Friends, I have a requirement to reset usage decision by creating a customer funtion button in tcode QA12 and reverse the posting quantity from restricted area to to be posted area. I have implemented SAP Note# 175842.So now decision is getting re

  • 6i Forms Word 2003 Mail Merge

    We have mail merge working from 6i forms with Word 97. We are going to Word 2003, but I am having trouble getting the mail merge to work. The example on Metalink, note 297410.1, seems to be directed at data files in row format. Our data file is in ta

  • Workflow Performance

    Hi All, I have a Performance Issue in Work flow. I modified BOR object created Subtype and accessed Change pointer tables to get the old and new data. It is working good in Development Server . When it is moved to Production performance of production

  • Wireless Access to iMac DVD Drive from MacBook Air

    Help please? Could access the IMac drive and DVDs from my MacBook Air until recently. Drive is no longer accessible. Have also lost ability to print remotely to printer attached to iMac (have tried re-setting permissions etc). Can also no longer acce