Encryption program does not work in IBM JDK

Hi
I have a encrypt, decrypt program, which does not work in IBM JDK
the code is as below, it gives PBEWithMD5AndDES does not exist kind of error when running with IBM JDK
import java.io.UnsupportedEncodingException;
import java.security.spec.AlgorithmParameterSpec;
import java.security.spec.KeySpec;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.spec.PBEParameterSpec;
public class MapsPasswordUtil
     Cipher ecipher;
     Cipher dcipher;
     // 8-byte Salt
     byte[] salt = { (byte) 0xA9, (byte) 0x9B, (byte) 0xC8, (byte) 0x32,
               (byte) 0x56, (byte) 0x35, (byte) 0xE3, (byte) 0x03 };
     // Iteration count
     int iterationCount = 19;
     public MapsPasswordUtil(String passPhrase)
          try
               KeySpec keySpec = new PBEKeySpec(passPhrase.toCharArray(), salt,
                         iterationCount);
               SecretKey key = SecretKeyFactory.getInstance("PBEWithMD5AndDES")
                         .generateSecret(keySpec);
               ecipher = Cipher.getInstance(key.getAlgorithm());
               dcipher = Cipher.getInstance(key.getAlgorithm());
               // Prepare the parameter to the ciphers
               AlgorithmParameterSpec paramSpec = new PBEParameterSpec(salt,
                         iterationCount);
               // Create the ciphers
               ecipher.init(Cipher.ENCRYPT_MODE, key, paramSpec);
               dcipher.init(Cipher.DECRYPT_MODE, key, paramSpec);
          } catch (java.security.InvalidAlgorithmParameterException e)
               e.printStackTrace();
          } catch (java.security.spec.InvalidKeySpecException e)
               e.printStackTrace();
          } catch (javax.crypto.NoSuchPaddingException e)
               e.printStackTrace();
          } catch (java.security.NoSuchAlgorithmException e)
               e.printStackTrace();
          } catch (java.security.InvalidKeyException e)
               e.printStackTrace();
     public String encrypt(String str)
          try
               // Encode the string into bytes using utf-8
               byte[] utf8 = str.getBytes("UTF8");
               // Encrypt
               byte[] enc = ecipher.doFinal(utf8);
               // Encode bytes to base64 to get a string
               return new sun.misc.BASE64Encoder().encode(enc);
          } catch (javax.crypto.BadPaddingException e)
               e.printStackTrace();
          } catch (IllegalBlockSizeException e)
               e.printStackTrace();
          } catch (UnsupportedEncodingException e)
               e.printStackTrace();
          return null;
     public String decrypt(String str)
          try
               // Decode base64 to get bytes
               byte[] dec = new sun.misc.BASE64Decoder().decodeBuffer(str);
               // Decrypt
               byte[] utf8 = dcipher.doFinal(dec);
               // Decode using utf-8
               return new String(utf8, "UTF8");
          } catch (javax.crypto.BadPaddingException e)
               e.printStackTrace();
          } catch (IllegalBlockSizeException e)
               e.printStackTrace();
          } catch (UnsupportedEncodingException e)
               e.printStackTrace();
          } catch (java.io.IOException e)
               e.printStackTrace();
          return null;
}

Works for me with the latest IBM JDK. You will need to specify your context i.e. what platform, what JDK/JRE etc etc etc.
P.S. That exception handling is rubbish.
Edited by: sabre150 on Mar 23, 2009 6:01 AM
I suspect that you are using JDK 1.5 and that you have fallen foul of the bug where key.getAlgorithm() does net return the correct value. You get round this by specifying it as             SecretKey key = SecretKeyFactory.getInstance("PBEWithMD5AndDES").generateSecret(keySpec);
            ecipher = Cipher.getInstance("PBEWithMD5AndDES");Of course if you are clever you will just define a static final constant for this algorithm.
Edited by: sabre150 on Mar 23, 2009 6:09 AM

Similar Messages

  • TS1702 Maps program does not work. In standard it only shows a grid. If I ask for a route it shows start and end point and three route boxes but nothing else. It does show directions. If I switch to hybrid it shows to routes but no roads. Background is a

    Maps program does not work. In standard it only shows a grid. If I ask for a route it shows start and end point and three route boxes but nothing else. It does show directions. If I switch to hybrid it shows to routes but no roads. Background is a blur.

    Do you have a question? This is a user to user help forum. Apple is not here only other users like yourself. You don't report problems to Apple here.
    By the way, it might help if you indicated where you are located.
    To complain to Apple use http://www.apple.com/feedback/ipad.html

  • I just signed up for a subscription to adobe reader paying EUR 24.40. The program does not work, and I can not even go to my personal page .... help ...?

    I just signed up for a subscription to adobe reader paying EUR 24.40.
    The program does not work, and I can not even go to my personal page .... help ...?

    Adobe Reader is free; it does not require a subscription.
    Did you subscribe to an online service like ExportPDF, PDF Pack, ...?
    What exactly does "not work" mean?

  • Hello Since yesterday evening. My itunse program does not work my mobile. Note  I update the program to ios7 Please help me Thank you

    hi
    Hello
    Since yesterday evening. My itunse program does not work my mobile.
    Note
    I update the program to ios7
    Please help me
    Thank you

    I found this strange glitch that wouldn't let me open my iTunes Store. I tried all the reset options and still iTunes would close a second after it opened. I fixed this. Instead of using the iTunes Store icon on your home page to open it. Go into music and click on store. It will say "Cannot Connect To Store". Just tap ok. Then tap on "featured" on the bottom of the screen. That will take you to the store front page. After that is loaded. Back out and the icon for iTunes Store on the home page should work just fine. Hope that helps.

  • I purchased a program on Mac App store and the program does not act as it should,  also was required to pay up front whereas had I went to the web site, ibank 4 I would have had 30 days free trial an would have found that the program does not work.?

    I purchased a program on Mac App store and the program does not act as it should,  also was required to pay up front whereas had I went to the web site, ibank 4 I would have had 30 days free trial an would have found that the program does not work.?

    Free trials are not available through the Mac App Store.
    Apple is not here. Apple does not answer questions here. This is a user to user support forum. There are only folks here who use Apple products.

  • Now a few of programs does not work with mountian lion. what to do?

    now a few of programs does not work with mountian lion. what to do?

    espons printer/scanner, toast titanum 5.2.1, intuos 4 wacom, appleworks, already updated ms office & order the upgrade for reunion which I hope it will work. 
    thank you mr michael allbritton for your help!

  • My program does not work properly. I run the program but it is not capable of adding any of my ebooks and when I connect my ereader, it recognises the device but  it does not add any ebook either.  I uninstalled the program and reinstalled again but nothi

    my program does not work properly. I run the program but it is not capable of adding any of my ebooks and when I connect my ereader, it recognises the device but  it does not add any ebook either.
    I uninstalled the program and reinstalled again but nothing gone better-
    What should I do?
    Best regards

    Do you have Logitech gaming software installed on the PC? If so, perhaps try the suggestion from the following post:
    Re: Everytime I close Itunes it loads back up

  • ISQLPLUS does not works after downgrading JDK.

    Hi,
    I am not sure if ISQLPLUS has anything to do with downgrading JDK. To my understand apache has its own classpath set. I have properly configure ISQLPLUS last week and no issues at all. This week, I am trying to downgrade my JDK (Sun) from 1.3.1 to 1.2.2. Soon after that i cannot access to my ISQLPLUS at all. It says FIle not found: Error 404. I haven't change any of my conf file, and apache start properly as well.
    I have a few JDK version on my machine at this point of time. 1.2.2 (IBM), 1.3.1(Sun), and 1.3.2 (Sun) . I am using them for different projects. And I believed Apache has its own version as well (1.7.1 ??).
    Any hints what am I getting Error 404?
    Thanks
    -KL

    What do you mean by "restoring definitions"?
    What EXACTLY is your problem?
    "does not works" is just a bit vague.

  • Encrypt Message does not work with new Plug-in 7.3

    I installed the new Email Security Plug-in 7.3 but now the Encrypt Message button does not work.  It is grayed out and unavailable when I attempt to create a new message. 
    I first tried installed 7.3 over the previous version but every time I opened Outlook I received an error message about XML not loading.  I uninstalled the plugin, rebooted and installed it clean and that took care of the XML message.  But I then found the encrypt button issue and have not been able to solve that issue.  This is not isolated to my machine as I have tried installing it on another machine that never had the plug-in installed before.                  

    My understanding is that they completely rewrote it, which is probably why an upgrade doesn't work well...
    I did get one way of deploying figured out, the stuff on page 3-20 has some errors. 
    Here's what I did that works:
         Do a clean install on a machine that doesn't have any plugin installed.
         Copy the C:\Users\All Users\Cisco\Cisco IronPort Email Security Plug-In\Common directory and its contents to a network accsible share, say \\fs1\share\pluginconfig, so you now have \\fs1\share\pluginconfig\Common, etc...
         Copy your BCE_Config_Signed.xml file to the Common folder
         Rename that to config_1.xml
         Edit the CommonEncryptionConfig.xml to have the following XML:
          Now you can push the install with a command line that references the folder (the example on page 3-20 is wrong, no 's' ):
                CiscoIronPortEmailSecurity-7-3-0-102.exe /exenoui /qn UseCustomConfig="\\fs\share\pluginconfig"
           (if you're doing it on the same machine you did the clean install with, you should uninstall it first...)
    Message was edited by: Ken Stieers

  • Program does not work after build

    Hi,
    I have built a program today that builds fine (no errors or warnings) but it fails when running the exe.  I am using drivers for a spectrum analyzer (Rohde & Schwarz FSG) and when one of these drivers is called, it returns an error.  Other drivers are run before this particular vi.  Anyone have any idea how to troubleshoot this?  I'm going to try and build the vi on its own and see if it works.  In the mean time, if anyone has any suggestions, please let me know.
    UPDATE: I built the file on its own and it still does not work.  Again, when I run it in developer mode, it works fine.
    VISA Write in rsspecan_core_write.vi->rsspecan_core_attribute_wr​ite_int.vi:3->subrsspecan_core_attribute_express.v​i:2->rsspecan Configure Averaging Type.vi:Instance:Instance           1 41Saved   rsspecan Configure Averaging Type .vi:1->rsspecan Configure Averaging Type.vi
    Thanks.

    I've decided to post the vi since it is free to download.  If anyone has an FSG and wants to build this file and see if they can run it, please do so.
    Attachments:
    rsspecan Configure Averaging Type.vi ‏31 KB

  • Program does not Work

    I have a for loop in which I am reading the content of an array.Also a method is called within the for loop the purpose of this method is to be able to jump to a another array index.
    I have written the program as shown below but it does not work.
    private class Executionionhandler implements ActionListener
    { public void actionPerformed(ActionEvent event)
    { for(int i=0;i<62;i++)
    { int x=array[i];
    int k=x+2;
    look(x);
    public void look(int j)
    { if(j==0)
    button.setText(�Readyl�);
    else if(j=1)
    button.setText(�Go�);
    else if(j=2)
    button.setText(�Stop�);
    else if(j==5)
    i=20;
    else button.setText(�Successful�);
    Any idea why or how can I achieve this?

    http://forum.java.sun.com/thread.jsp?thread=265406&forum=31&message=1006380
    http://forum.java.sun.com/thread.jsp?thread=265328&forum=31&message=1006048
    http://forum.java.sun.com/thread.jsp?thread=265310&forum=31&message=1005982
    http://forum.java.sun.com/thread.jsp?thread=265307&forum=31&message=1005979
    http://forum.java.sun.com/thread.jsp?thread=265307&forum=31&message=1005969

  • My java programe does not work

    Hi
    I createda java programme with jdeveloper . I compiled my code in all of version (1.3, 1.4, 1.5, 1.6 and default).
    But when i try to run my programme in other computers that have j2SE Runtime Environment 5.0 update 11, or java Runtime 2 Environment SE 1.3 - 1.4,
    my programme doesnot work.
    how can i fix this problem.

    Which Jdev version?
    What exactly do you mean by 'does not work'?
    Timo

  • File concatenating program does not work

    Hello, im quite new to java therefore it may only be a simple solution.
    The program reads mulitple files off the command line and then should join them up (concatenate) in a new file called "NewFile".
    The problem is it only prints the content of one of the files to the new file.
    Here is my code:
    /*Write an application which concatenates files. The name of
    *each file is supplied on the command line. The output file
    *consists of all the contents of the first file, followed by
    *all the contents of the second file, and so on. One of the
    *slides in the lecture may help.
    import java.util.*;
    import java.io.*;
    public class Concatenate
         public void process (String[] argStrings) throws Exception
              String fileName = argStrings[0];
              String contents = null;
              System.out.println();
              System.out.println("Conatenated contents of files:");
              System.out.println();
              for (int index = 0; index < argStrings.length; index++)
                   Scanner sc = new Scanner(new File(argStrings[index]));
                   contents = sc.nextLine();
                System.out.println(contents);
                   sc.close();
              PrintStream output = new PrintStream("NewFile.txt");
              output.println(contents);
            output.close();
    }Thanks anyone
    John

    // put this before the for loop
    PrintStream output = new PrintStream("NewFile.txt");
    // put this inside the for loop
    output.println(contents);Now, do you understand why you have to do that?

  • A serial number I received as part of my school program does not work.

    what do I need to do?

    Have you submitted your proof of eligibility?  If so please see http://forums.adobe.com/message/4635085#4635085.

  • This program is well compiled but does not work.

    I would like to know why this program does not work properly:
    the idea is :
    1. the user introduces a text as a string
    2.the progam creates a file (with a FileOutputStream)
    3. then this file is encripted according to DES (using JCE, cipheroutputStream)
    4.the new filw is an encripte file, whose content is introduced in a string (with a FileInputStream)
    (gives no probles of compilation!!)
    (don know why it does not work)
    here goes the code:
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    import java.io.*;
    import java.security.*;
    import javax.crypto.*;
    public class cuadro extends Applet{
         private TextArea area1 =new TextArea(5,50);
         private TextArea area2 =new TextArea(5,50);
         private Button encriptar=new Button("encriptar");
         private Button decriptar=new Button("decriptar");
         public cuadro(){
              layoutApplet();
              encriptar.addActionListener(new ButtonHandler());
              decriptar.addActionListener(new ButtonHandler());
              resize(400,400);
              private void layoutApplet(){
              Panel keyPanel = new Panel();
              keyPanel.add(encriptar);
              keyPanel.add(decriptar);
              Panel textPanel = new Panel();
              Panel texto1 = new Panel();
              Panel texto2 = new Panel();
              texto1.add(new Label("               plain text"));
              texto1.add(area1);
              texto2.add(new Label("               cipher text"));
              texto2.add(area2);
              textPanel.setLayout(new GridLayout(2,1));
              textPanel.add(texto1);
              textPanel.add(texto2);
              setLayout(new BorderLayout());
              add("North", keyPanel);
              add("Center", textPanel);
              public static String encriptar(String text1){
              //generar una clave
              SecretKey clave=null;
              String text2="";
              try{
              FileOutputStream fs =new FileOutputStream ("c:/javasoft/ti.txt");
              DataOutputStream es= new DataOutputStream(fs);
                   for(int i=0;i<text1.length();++i){
                        int j=text1.charAt(i);
                        es.write(j);
                   es.close();
              }catch(IOException e){
                   System.out.println("no funciona escritura");
              }catch(SecurityException e){
                   System.out.println("el fichero existe pero es un directorio");
              try{
                   //existe archivo DESkey.ser?
                   ObjectInputStream claveFich =new ObjectInputStream(new FileInputStream ("DESKey.ser"));
                   clave = (SecretKey) claveFich.readObject();
                   claveFich.close();
              }catch(FileNotFoundException e){
                   System.out.println("creando DESkey.ser");
                   //si no, generar generar y guardar clave nueva
              try{
                   KeyGenerator claveGen = KeyGenerator.getInstance("DES");
                   clave= claveGen.generateKey();
                   ObjectOutputStream claveFich = new ObjectOutputStream(new FileOutputStream("DESKey.ser"));
                   claveFich.writeObject(clave);
                   claveFich.close();
              }catch(NoSuchAlgorithmException ex){
                   System.out.println("DES key Generator no encontrado.");
                   System.exit(0);
              }catch(IOException ex){
                   System.out.println("error al salvar la clave");
                   System.exit(0);
         }catch(Exception e){
              System.out.println("error leyendo clave");
              System.exit(0);
         //crear una cifra
         Cipher cifra = null;
         try{
              cifra= Cipher.getInstance("DES/ECB/PKCS5Padding");
              cifra.init(Cipher.ENCRYPT_MODE,clave);
         }catch(InvalidKeyException e){
              System.out.println("clave no valida");
              System.exit(0);
         }catch(Exception e){
              System.out.println("error creando cifra");
              System.exit(0);
         //leer y encriptar el archivo
         try{
              DataInputStream in = new DataInputStream(new FileInputStream("c:/javasoft/ti.txt"));
              CipherOutputStream out = new CipherOutputStream(new DataOutputStream(new FileOutputStream("c:/javasoft/t.txt")),cifra);
              int i;
              do{
                   i=in.read();
                   if(i!=-1) out.write(i);
              }while (i!=-1);
              in.close();
              out.close();
         }catch(IOException e){
              System.out.println("error en lectura y encriptacion");
              System.exit(0);
         try{
              FileInputStream fe=new FileInputStream("c:/javasoft/t.txt");
              DataInputStream le =new DataInputStream(fe);
                   int i;
                   char c;
                   do{
                        i=le.read();
                        c= (char)i;
                        if(i!=-1){
                        text2 += text2.valueOf(c);
                   }while(i!=-1);
                        le.close();
              /*}catch(FileNotFoundException e){
                   System.out.println("fichero no encontrado");
                   System.exit(0);
              }catch(ClassNotFoundException e){
                   System.out.println("clase no encontrada");
                   System.exit(0);
              */}catch(IOException e){
                   System.out.println("error e/s");
                   System.exit(0);
              return text2;
         class ButtonHandler implements ActionListener{
         public void actionPerformed(ActionEvent e){
              try{
              if (e.getActionCommand().equals(encriptar.getLabel()))
                   //     area2.setText(t1)
                   area2.setText(encriptar(area1.getText()));
                   //area2.setText("escribe algo");
                   else if (e.getActionCommand().equals(decriptar.getLabel()))
                        System.out.println("esto es decriptar");
                        //area2.setText("hola");
         }catch(Exception ex){
              System.out.println("error en motor de encriptacion");
                   //else System.out.println("no coge el boton encriptado/decript");

    If you don't require your code to run as an applet, you will probably get more mileage from refactoring it to run as an application.
    As sudha_mp implied, an unsigned applet will fail on the line
    FileInputStream fe=new FileInputStream("c:/javasoft/t.txt");
    due to security restrictions. (Which, incidentally, are there for a very good reason)

Maybe you are looking for

  • Ipod nano 2nd gen

    ipod nano 2nd gen will not connect to my computer or itunes but when plug in the usb it charges it

  • Spry accordion problem with IE

    I tried to make a site using all different spry-widgets, so I made tabbed panels and in them accordion panels (and in other panels other spry-things). It works well in FF but in IE the accordionpanels stay all open. Can someone help me out. Many than

  • I get: Unknown error (-50). can not syncronize your ipod!!!!!

    Hi I have 60GB ipod with itunes7 windows XP pro I cant see any artwork in my ipod because when I check the option to see artwork and I syncronize(update) my ipod a message pops up: Unknown error (-50). can not syncronize your ipod!!!!! it is somethin

  • Create iCloud calendar with Applescript

    I use the create calendar with name "" and it makes it "On My Mac". Is there any way to make it in iCloud instead? Thanks

  • Undo command no longer works, instead it's "Undo camera navigation"

    Hi, My undo function in motion has been replaced by "undo camera navigation." Maybe I pressed something to make this happen? Does anyone know how to get my undo function back? Thanks, Ken