Can't decrypt binary file with PBE

Hi,
I'm writing an simple file transfer application using UDP that encrypts the data
before sending it with PBEWithMD5AndDES. Text files are encrypted and
decrypted fine, but binary files such as a JPG/EXE/DOC... are messed up
and an application can't open them on the other side. Has anyone experienced
such a problem?
Thanks

Below are my encrypt and decrypt functions.
Thanks in advance.
        public  byte[] encrypt(byte[] data)
             PBEKeySpec pbeKeySpec;
             PBEParameterSpec pbeParamSpec;
             SecretKeyFactory keyFac;
             ByteArrayOutputStream b=null;
             DataOutputStream d =null;
             //      Salt
             byte[] salt = {
                       (byte)0xc7, (byte)0x73, (byte)0x21, (byte)0x8c,
                    (byte)0x7e, (byte)0xc8, (byte)0xee, (byte)0x99
             //      Iteration count
             int count = 1000;
             // Create PBE parameter set
             pbeParamSpec = new PBEParameterSpec(salt, count);
             try{
                  pbeKeySpec = new PBEKeySpec(sessionPassword.toCharArray());
                  keyFac = SecretKeyFactory.getInstance("PBEWithMD5AndDES","SunJCE");
                  SecretKey pbeKey = keyFac.generateSecret(pbeKeySpec);
                  // Create PBE Cipher
                  Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES","SunJCE");
                  // Initialize PBE Cipher with key and parameters
                  pbeCipher.init(Cipher.ENCRYPT_MODE, pbeKey, pbeParamSpec);
                  b = new ByteArrayOutputStream();
                  d = new DataOutputStream(b);
                  // create CipherOutputStream
                  CipherOutputStream out = new CipherOutputStream( b, pbeCipher );
                  // write contents to file and close
                  try {
                       for ( int i = 0; i < data.length; i++ )
                            out.write(data);
                         out.flush();
                    out.close();
               // handle IOException
               catch ( IOException exception ) {
                    exception.printStackTrace();
          catch(Exception e){}
          return(b.toByteArray());
     public byte[] decrypt(byte[] data)
          PBEKeySpec pbeKeySpec;
          PBEParameterSpec pbeParamSpec;
          SecretKeyFactory keyFac;
          byte[] decryptedData=null;
          //      Salt
          byte[] salt = {
                    (byte)0xc7, (byte)0x73, (byte)0x21, (byte)0x8c,
                    (byte)0x7e, (byte)0xc8, (byte)0xee, (byte)0x99
          //      Iteration count
          int count = 1000;
          // Create PBE parameter set
          pbeParamSpec = new PBEParameterSpec(salt, count);
          try{
               pbeKeySpec = new PBEKeySpec(sessionPassword.toCharArray());
               keyFac = SecretKeyFactory.getInstance("PBEWithMD5AndDES","SunJCE");
               SecretKey pbeKey = keyFac.generateSecret(pbeKeySpec);
               // Create PBE Cipher
               Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES","SunJCE");
               // Initialize PBE Cipher with key and parameters
               pbeCipher.init(Cipher.DECRYPT_MODE, pbeKey, pbeParamSpec);
               Vector fileBytes = new Vector();
               ByteArrayInputStream b = new ByteArrayInputStream(data);
               CipherInputStream in = new CipherInputStream( b, pbeCipher );
               byte contents = ( byte ) in.read();
               while ( contents != -1 )
                    fileBytes.add( new Byte( contents ) );
                    contents = ( byte ) in.read();
               in.close();
               decryptedData = new byte[ fileBytes.size() ];
               for ( int i = 0; i < fileBytes.size(); i++ )
                    decryptedData[ i ] = (( Byte )fileBytes.elementAt( i )).byteValue();
          catch(Exception e){Gui.chatArea.append("exception:"+e+"\n");}
          return(decryptedData);

Similar Messages

  • I have written a binary file with a specific header format in LABVIEW 8.6 and tried to Read the same Data File, Using LABVIEW 7.1.Here i Found some difficulty.Is there any way to Read the Data File(of LABVIEW 8.6), Using LABVIEW 7.1?

    I have written a binary file with a specific header format in LABVIEW 8.6 and tried  to Read the same Data File, Using LABVIEW 7.1.Here i Found some difficulty.Is there any way to Read the Data File(of LABVIEW 8.6), Using LABVIEW 7.1?

    I can think of two possible stumbling blocks:
    What are your 8.6 options for "byte order" and "prepend array or string size"?
    Overall, many file IO functions have changed with LabVIEW 8.0, so there might not be an exact 1:1 code conversion. You might need to make some modifications. For example, in 7.1, you should use "write file", the "binary file VIs" are special purpose (I16 or SGL). What is your data type?
    LabVIEW Champion . Do more with less code and in less time .

  • How can I print a file with mixed page orientation in windows 8.1?

    I have a win 7 and a win 8.1 computer.  I have a file which contains both landscape and portrait pages.  The file prints correctly with the mixed orientation from the win 7 pc, but will only print with either landscape or portrait on the win 8.1 pc. 
    I am using Adobe reader XI on the win 7 pc and adobe touch on the win 8.1 pc

    ส่งจาก จดหมายของ Windows
    จาก: Pat Willener
    ส่งเมื่อ: จ. 5 มกราคม 2558 6:15
    ถึง: thang dinhvan
    How can I print a file with mixed page orientation in windows 8.1?
    reply from Pat Willener in Adobe Reader Touch for Windows 8 - View the full discussion 
    I have a win 7 and a win 8.1 computer.  I have a file which contains both landscape and portrait pages.  The file prints correctly with the mixed orientation from the win 7 pc, but will only print with either landscape or portrait on the win 8.1 pc. 
    I am using Adobe reader XI on the win 7 pc and adobe touch on the win 8.1 pc
    If the reply above answers your question, please take a moment to mark this answer as correct by visiting: https://forums.adobe.com/message/7064031#7064031 and clicking ‘Correct’ below the answer
    Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page:
    Please note that the Adobe Forums do not accept email attachments. If you want to embed an image in your message please visit the thread in the forum and click the camera icon: https://forums.adobe.com/message/7064031#7064031
    To unsubscribe from this thread, please visit the message page at , click "Following" at the top right, & "Stop Following"
    Start a new discussion in Adobe Reader Touch for Windows 8 by email or at Adobe Community
    For more information about maintaining your forum email notifications please go to https://forums.adobe.com/thread/1516624.

  • I can't open PDF files with adobe flash player

    I have installed it and whenever I try to open pdf files it says I need to agree with your liscens and you do that automatically when you download it. I have followed all your instructions on your website and uninstalled it and installed again, but I can't open pdf files with it. I don't know what the problem is exactly, but it's really frustrating..

    Flash Player CANNOT open PDFs because they AREN'T Flash Documents.
    Adobe Reader opens PDFs.
    To accept the license agreement (NOT the one you accepted to download or install - the one for USE)
    Windows:
    Go to: C/Program Files(x86)/Adobe/Reader 11.0/Reader and double click the eula.exe file. The license agreement will open for you to accept.
    Mac:
    Go to: Mac HD/Applications and double click the Reader app. The license agreement will open THE FIRST TIME you open it.

  • I can't read a file with the ext PDF the sender informed me that the file was reset to PDF.

    I can't read a file with the .ext PDF the sender informed me that the file was reset to PDF. But when I tried to open it the caption box informed me"the file is not in PDF format. I suspect the sender simply changed the file .ext which is why I can't open it! What can I do about it! I am working on an iPad.
    Thanks
    Mr Jim Lapthorn

    If the document is not, in fact, a PDF, then you will need to get your sender to provide a PDF.
    Can you open this document in any other application?

  • I can't open pps files with FF4. I have Powerpoint Viewer installedAny suggestions?

    I can open Powerpoint (pps) files with Google Chrome but not Firefox 4. How do I get FF4 to associate pps files with the Powerpoint Viewer that is installed on my computer?

    Many thanks!!!  This works and is probably the best fix for now.  Thank you!!!
    Date: Wed, 30 Jan 2013 10:58:01 -0800
    From: [email protected]
    To: [email protected]
    Subject: I can't open NEF files with PS Elements9 (Mac) and have just performed all avail. updates
        Re: I can't open NEF files with PS Elements9 (Mac) and have just performed all avail. updates
        created by 99jon in Photoshop Elements - View the full discussion
    For the D600 NEF's you have two alternatives: (1) Upgrade to PSE 11. (2) Download and install the free Adobe DNG converter to convert your raw files to the Adobe universal Raw format and the files will open in all versions of PSE (keep your originals as backups and for use in the camera manufactures software)  Windows download click here DNG Converter 7.3  Mac download click here DNG Converter 7.3  You can convert a whole folder of raw images in one click. See this quick video tutorial: You Tube click here for DNG Converter tutorial
         Please note that the Adobe Forums do not accept email attachments. If you want to embed a screen image in your message please visit the thread in the forum to embed the image at http://forums.adobe.com/message/5034913#5034913
         Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/5034913#5034913
         To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/5034913#5034913. In the Actions box on the right, click the Stop Email Notifications link.
         Start a new discussion in Photoshop Elements by email or at Adobe Community
      For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.

  • I can't open NEF files with PS Elements9 (Mac) and have just performed all avail. updates

    I can't open NEF files with PS Elements9 (Mac) and have just performed all avail. updates.  What to do?

    Many thanks!!!  This works and is probably the best fix for now.  Thank you!!!
    Date: Wed, 30 Jan 2013 10:58:01 -0800
    From: [email protected]
    To: [email protected]
    Subject: I can't open NEF files with PS Elements9 (Mac) and have just performed all avail. updates
        Re: I can't open NEF files with PS Elements9 (Mac) and have just performed all avail. updates
        created by 99jon in Photoshop Elements - View the full discussion
    For the D600 NEF's you have two alternatives: (1) Upgrade to PSE 11. (2) Download and install the free Adobe DNG converter to convert your raw files to the Adobe universal Raw format and the files will open in all versions of PSE (keep your originals as backups and for use in the camera manufactures software)  Windows download click here DNG Converter 7.3  Mac download click here DNG Converter 7.3  You can convert a whole folder of raw images in one click. See this quick video tutorial: You Tube click here for DNG Converter tutorial
         Please note that the Adobe Forums do not accept email attachments. If you want to embed a screen image in your message please visit the thread in the forum to embed the image at http://forums.adobe.com/message/5034913#5034913
         Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/5034913#5034913
         To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/5034913#5034913. In the Actions box on the right, click the Stop Email Notifications link.
         Start a new discussion in Photoshop Elements by email or at Adobe Community
      For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.

  • How can I associat ".swf" files with flashlite 2.1

    How can I associate ".swf" files with flashlite 2.1? When I
    install flash lite 2.0,it can do ---- click .swf files system can
    autoly use flashlite to play.But now I install flashlite 2.1,it
    lost this ability return as "unknow files formate".
    Now,how can I reassociate ".swf" with flashlite 2.1?
    first: I must use flashlite 2.1.
    second:I must click .swf file directly.
    I know another way to open :open the player and then find the
    .swf,and open it. But ,unfortunately,I can not use this way to
    open.Now I will be looking for another way.

    unfortunately, the 2.1 developer edition you have installed
    has not overwritten the original version integrated into the
    symbian OS by the manufacturer. This means that the only way to
    open the 2.1 files is to open the 2.1 player from your apps menuu,
    and click on the swf file. You will only get direct access if the
    updated player is in a firmware update for you handset.
    Matt
    http://www.outside-media.co.uk/blog

  • I have a problem with the mac can not read video files with the extension IMOD. How can I solve this problem?

    I have a problem with the mac can not read video files with the extension IMOD. How can I solve this problem?

    By doing a Google search. 

  • Can't i exchange files with bluetooth blackberry

    Why can't i exchange files with bluetooth blackberry i am getting a error message saying " cannot connect the device"

    Hello,
    Please provide the exact steps you are conducting, on both devices, in the exact order you are making the attempt. Also, are both devices BBs? Further, please provide the exact OS level (all 4 octets please) of the BB's that are involved in the attempt.
    Thanks!
    Occam's Razor nearly always applies when troubleshooting technology issues!
    If anyone has been helpful to you, please show your appreciation by clicking the button inside of their post. Please click here and read, along with the threads to which it links, for helpful information to guide you as you proceed. I always recommend that you treat your BlackBerry like any other computing device, including using a regular backup schedule...click here for an article with instructions.
    Join our BBM Channels
    BSCF General Channel
    PIN: C0001B7B4   Display/Scan Bar Code
    Knowledge Base Updates
    PIN: C0005A9AA   Display/Scan Bar Code

  • Sum Encrypt does not recognize a copy of a file through linux. How decrypt this file with Sum Encrypt?

    Sum Encrypt does not recognize a copy of a file through linux to Mac 0S9. How decrypt this file with Sum Encrypt?

    Hello, and welcome to Apple Support Communities!
    I am not familiar with the program that you list, however files in OS 9 use things called Resource Forks (rather than file extensions) for filetype and creator.
    If you sent a file through Linux these resource forks probably got stripped and now the file is nothing to your Macintosh.
    It is best to BinHex your files (.hqx) before leaving the HFS file system so that their resource forks are preserved.
    Regards,
    Ryan

  • How can I export a file with transparent background?

    Hi all,
    I know InDesign doesn't allow to export a PNG file, but I need my file to be in image file format with transparent background.
    I'm still learning so I am stuck here. How can I export a file with transparent background?

    If you can't get the PNG file export to work, you can export a pdf and open it in Photoshop, from there you can save it as whatever you like.

  • Can i access swf files with your product?

    can i access swf files with dreamweaver?

    You will need Flash as well as Dreamweaver.
    Follow these instructions http://help.adobe.com/en_US/dreamweaver/cs/using/WSc78c5058ca073340dcda9110b1f693f21-7ad0a .html

  • Can't save any file with any name-InDesign CC

    can't save any file with any name-file DBTmp4376-863643269 is damaged (error code:0)
    InDesign CC, OS version 10.9.1
    I explored solutions to failure in background task alert which did not work. Been using adobe products since they came on the scene. Nothing like this. Please help.

    I'm using version 9.2.
    Yes, it started with a new file. Support gave me the solution to save it to my desktop which worked. When I put it back in the original folder and opened/save it would not save to that folder. Created a new folder and was able to open & save to the new folder. That seems to be a workable solution. How a folder can become corrupt is a bit scarey.
    In experimenting with solutions I received another error "failure in background task alert" and discovered CS5 problems with background task.
    However the solutions for CS5 did not work in my incidence.
    I sure would like to prevent this from happening again. If you have any insights please share them. Otherwise I will just accept the experience as another computer workaround and be thankful that I have it.
    Thanks for responding.

  • Can't open .wmf files with Illustrator

    I'm using Creative Suite CS2 on a PC/Windows XP operating system.
    I'm suddenly unable to launch Illustrator when I try to open a .wmf file from within Windows Explorer. Instead, I get an error message that the file itself is not a valid program (DUH!).
    I also cannot open them with the "Edit Original" command in InDesign.
    I have tried changing the "Opens With Program..." option in the file properties from within Windows Explorer over and over.
    Oddly, I can always open .wmf files with Illustrator from within Adobe Bridge, simply by double-clicking the file. And of course, I can open them from within Illustrator by simply going to "open file".
    But I really want to be able to use the "Edit Original" feature in InDesign to launch and open .wmf files in Illustrator.
    Anybody know what's going on? Is this a Windows problem, an Illustrator problem or an InDesign problem? And how do I fix it?
    Thanks so much for any suggestions.

    I'm sorry you're having this problem with Illustrator.  Would you mind reposting over on the Illustrator forums?  You've posted in the AIR forum and I think you'll have better luck over there.
    Thanks,
    Chris

Maybe you are looking for

  • I see/play TV Shows in iTunes view but not on iPhone

    When I connect my iPhone4S to my MBAir and view the iPhone's files (via iTunes) I see that there are 37 "TV Shows" listed.  I can even click the play button and they play (in iTunes, on my computer).  My iPhone shows (at the bottom of the iTunes wind

  • How to Upgrade System HDD on a T43?

    Hi everybody.  I'm new here, so forgive me if this has been asked and answered already.  I've searched the forums and the KB, and haven't found quite the answer I'm looking for. Is there a good, step-by-step guide for upgrading the system hard drive

  • How to veto a JComboBox selection change in ItemListener

    I have a JComboBox whose current value is tied to some data cached in my application. I want to be able to examine the selection in an ItemListener attached to the JComboBox, and if the value is different than what I have cached, I want to ask the us

  • RFIDITVCL : problem with variation notes

    Hi Experts, I have implemented the sapnote 1639418 "RFIDITVCL: 3000 Euro Communication additional changes", but I have a problem with variation notes related to specific invoices in same year...the user guide in the note says that they are clubbed to

  • I just downloaded Yosemite and my email doesn't work.

    When I click on the email icon it will import and migrate all data but then I get a message that says it failed.