Jump to content
Excelsior Forums
Andy

Problem with encryption/decryption

Recommended Posts

I get the following exception when trying to initialize a SecretKeyFactory:

"Algorithm PBEWithMD5AndDES not available"

Here's the code:

import java.security.Security;
import java.security.Provider;
import java.security.GeneralSecurityException;

import javax.crypto.Cipher;
import javax.crypto.CipherInputStream;
import javax.crypto.spec.SecretKeySpec;

import javax.crypto.spec.PBEKeySpec;
import javax.crypto.spec.PBEParameterSpec;
import javax.crypto.SecretKeyFactory;
import javax.crypto.SecretKey;




public class Decrypt {

//----------------------------------------------------------------- CONSTRUCTOR

 /**
  * Create a new decrypt class
  */
 public Decrypt() {
   byte[] salt = {(byte)0x01, (byte)0x02, (byte)0x04, (byte)0x08, (byte)0x10, (byte)0x12, (byte)0x20, (byte)0x24};

   System.out.println("Decrypt");

   Provider sunJce = new com.sun.crypto.provider.SunJCE();
   Security.addProvider(sunJce);


   try {



     // PBE parameter set
     pbeParamSpec = new PBEParameterSpec(salt, 23);
     keyFac       = SecretKeyFactory.getInstance("PBEWithMD5AndDES");

     char[] passw = "Password".toCharArray();

     pbeKeySpec = new PBEKeySpec(passw);
     pbeKey     = keyFac.generateSecret(pbeKeySpec);

     // PBE Cipher
     pbeCipherDecr = Cipher.getInstance("PBEWithMD5AndDES");

   }
   catch (GeneralSecurityException gse) {
     System.out.println("Decrypt(): "+gse.getMessage());
   }
 }

//-------------------------------------------------------------- PUBLIC METHODS



 public static void main(String[] args) {
   Decrypt d = new Decrypt();
 }



//----------------------------------------------------------- PRIVATE CONSTANTS




//----------------------------------------------------------- PRIVATE VARIABLES

 private Cipher pbeCipherDecr;
 private Cipher cipherDecr;
 private PBEParameterSpec pbeParamSpec;
 private PBEKeySpec pbeKeySpec;
 private SecretKeyFactory keyFac;
 private SecretKey pbeKey;
 private SecretKeySpec blKey; 



}

When running this class under JRE I get the output 'Decrypt', but when I run the compiled class (compiled with JET) I get the exception.

I'm evaluating JET excelsior and I'm using jdk1.4 which includes the JCE package.

Anybody know the solution??

Best Regards

Andy

Share this post


Link to post
Share on other sites

snowman,

Thanks for your reply, but I still have problems.

I did as you said and removed JCE related files from bod.zip and sym.zip. I used the JCE sample and exchanged the DHKeyAgreement3.java with my  Decrypt.java (changed the .prj and build.bat).

Now I get the following exception:

Exception in thread "main" java.lang.ExceptionInInitializerError

Caused by: java.lang.SecurityException: Cannot set up certs for trusted CAs

I've also tried to create a new project using the graphical frontend with the same result. I've tried to 'Bind with classes' and 'Bind to the executable' for the local_policy.jar file and the US_export_policy.jar file.

Anyone know a solution for this problem?

//Andy

Share this post


Link to post
Share on other sites

I have similar problems, one throws exception "java.security.NosuchAlgorithmException", when I am using the java.crypto to decrypt. Though it works fine when used as a jar file.

However, the other one is more interesting.  It occurs when I try to verify a digital signature. It throws "java.security.NoSuchAlgorithmException: class configured for KeyFactory(provider; SunRsaSign)cannot be found.

com.sun.rsajca.JSA_RSAKeyFactory".

What is interesting here is that it works fine as a jar file. And also works fine if I run the jet compiled exe on my developer machine (Windows XP). Now I deploy it to another machine, and it throws the above Exception.

It has driven me mad now. Almost want to give up and fall back to jar.

Any help?

Best regards,

su

Share this post


Link to post
Share on other sites

Our engineers need to be able to reproduce the problem. Would anybody who is affected be so kind and email us a sample Java encryption program that is known to work as a jar but refuses to work as an EXE? Please do not forget to include the respective JET project and .bat files and to describe the environment (at least versions of the OS and JDK).

Please email your sample to java@excelsior-usa.com

Share this post


Link to post
Share on other sites

Ok,

I have composed a test and send the source codes to the engineer team. Wish this would get solved soon.

Thanks.

su

Share this post


Link to post
Share on other sites

>>I also experienced with >>java.security.NoSuchAlgorithmException: class ... not >>found (sun.security.provider.MD5) on a deployment >>machine. I had no problem on the development >>machine, nor running as JAR on the deployment box. >>By the way, I used JET v2.51 Standard Edition.

>>This is really stopping my release!

Per Tech Support - after adding the additional DLLs through the Advance Options of the JetPack, I no longer had this exception.

Share this post


Link to post
Share on other sites

×