Java Cryptography Under Linux (Weird Bug)

Hi,
   Does anyone know why the following simple code does not work under Linux? It works perfectly fine under Windows but I am no security expert.

The actual crypto functions:

import java.io.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import java.util.*;


public class SecurityAgent
{
    public static Cipher PBECipher;
    public static SecretKey PBEKey;
    public static PBEKeySpec PBEKeySpecification;
    public static PBEParameterSpec PBEParamSpec;
    public static final byte[] Salt = {(byte)0xc7, (byte)0x73,
        (byte)0x21, (byte)0x8c, (byte)0x7e, (byte)0xc8, (byte)0xee, (byte)0x99};
    public static final int Count = 20;
   
    public static void InitiateCipher(int mode, String idString)
    {
        try
        {
            PBEParamSpec = new PBEParameterSpec(Salt, Count);
            PBEKeySpecification = new PBEKeySpec(idString.toCharArray());
            SecretKeyFactory keyFac = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
            PBEKey = keyFac.generateSecret(PBEKeySpecification);
            PBECipher = Cipher.getInstance("PBEWithMD5AndDES");
            SecurityAgent.PBECipher.init(mode, SecurityAgent.PBEKey, SecurityAgent.PBEParamSpec);
        }
        catch(Exception e) {}
    }
   
    public static void oneWayHash(InputStream incoming, OutputStream outgoing,
        String idString, boolean isEncrypting)
    {
        try
        {
            if(isEncrypting)
            {
                InitiateCipher(Cipher.ENCRYPT_MODE, idString);
                InputStream In = new BufferedInputStream(incoming);
                CipherOutputStream Out = new CipherOutputStream(outgoing, SecurityAgent.PBECipher);
                int i;
                while ((i = In.read()) != -1)
                    Out.write(i);
                Out.flush();
                Out.close();
                In.close();
            }
            else
            {
                InitiateCipher(Cipher.DECRYPT_MODE, idString);
               
                CipherInputStream In = new CipherInputStream(incoming, SecurityAgent.PBECipher);
               
                OutputStream Out = new BufferedOutputStream(outgoing);
                int i;
                while ((i = In.read()) != -1)
                    Out.write(i);
                Out.flush();
                Out.close();
                In.close();
            }
        }
        catch(Exception e) {}
    }
}

The testing program:



import java.security.*;
import java.io.*;

// testing code
public class Tester {
   
   
    public static void main(String[] args) throws Exception
   
    {
       
        // Testing in put password
        String password = "myPassword";
       
       
        // Create the encrypted password
        ByteArrayInputStream password_clear = new ByteArrayInputStream(password.getBytes());
        ByteArrayOutputStream password_encrypted = new ByteArrayOutputStream();
        SecurityAgent.oneWayHash(password_clear, password_encrypted, "myIdString", true);
       
        // Decode the encrypted password
        ByteArrayInputStream password_recrypted =
        new ByteArrayInputStream(password_encrypted.toString().getBytes());
        ByteArrayOutputStream password_reclear = new ByteArrayOutputStream();
        SecurityAgent.oneWayHash(password_recrypted, password_reclear, "myIdString", false);
       
       
       
        // Print out results
        System.out.println("Clear password=" + password);
        System.out.println("Encrypted password=" + password_encrypted.toString());
        System.out.println("Decrypted value of Encrypted password=" + password_reclear.toString());
       
    } // end main
   
} // end class

Any help is appreciated!
NGInterfaceAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

objectsCommented:
>        catch(Exception e) {}

if you ignore exceptions it makes it hard to know the reason

        catch(Exception e) { e.printStackTrace(); }

Probable reason is that the security provider is not available to your linux jre


0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CEHJCommented:
>>does not work

Meaning?

>>catch(Exception e) {}

Ignoring exception won't help diagnosis ;-)
0
NGInterfaceAuthor Commented:
Geez, never mind...the problem went away by itself :-P
0
CEHJCommented:
8-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.