I have translated some c code that we use to encrypt files.  I have a problem when I 
try to move the code to another machine.

I wrote the code on a sun under solaris 8, using java 1.4.0-b92.
The other machine I am trying is also solair 8, with the same build.
It will not work on the second machine if I compile it there, or copy the class file. 
I 
get no error messages, but I cannot encrypt and decrypt a file successfully

the relevent methods:

private String crypt(String inPut, int mode) throws Exception {
        Cipher crCipher = Cipher.getInstance("Blowfish/CBC/PKCS5Padding);
        String iV = "";
        String cText = inPut;
        byte[] encodedIV;
        AlgorithParameters algParams;
        if (mode == Cipher.DECRYPT_MODE) {
                encodedIV = input.substring(0,8).getBytes();
                cText = input.substring(8);
                IvParameterSpec specIV = new IvParameterSpec(encodedIV);
                crCipher.init(mode, blowfishKey, specIV);
        } else {
                crCipher.init(mode, blowfishKey);
                algParams = crCipher.getParameters();
                if (algParams != null) {
                        encodedIV = crCipher.getIV();
                        iV = new String(encodedIV);
                }
        }
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ByteArrayInputStream  bis = new ByteArrayInputStream (cText.getBytes());
        CipherOutputStream cos = new CipherOutputStream(bos.crCipher);

        int outLength = 0;
        byte[] buffer = new byte[8192];
        while ((outLength = bis.read(buffer)) != -1) {
                cos.write(buffer,0,outLength);
        }
        bis.close();
        cos.close();
        cText = iV + bos.toString();
        return cText;
}

the key is set like this:

SecretKeySpec blowfishKey;
String newKey = "Some random string of bytes";
Provider sunJCE = new com.susn.crypto.provider.SunJCE();
Security.addProvider(sunJCE);
KeyGenerator kgen = KeyGenerator.getInstance("Blowfish");
kgen.init(448);
SecretKey skey = kgen.generatorKey();
byte[] raw = newKey.getBytes();
blowfishKey = new SecretKeySpec(raw, "Blowfish");


                
} 

Reply via email to