decrypting a 3des file
843810Oct 21 2002 — edited Oct 23 2002Hello,
I'm using JCE1.2.2/JDK1.3 and I have the following problem.
I encrypted a file with openssl 0.9.6:
-----
openssl des3 -e -in dec.txt -out enc.txt -K 003a54b58c5f3845bcf2a34585d46363242ffce32d3d5f01 -iv 0000000000000000
------
When I use my java program only the first 8 bytes of my file wil
be decryted.
See this:
-----------------
mouse Tastatur etc
------------------
output:
-------------------
mouse Ta�0.M..,�
------------------------------
This ist my Java code:
public class TripleDesDec {
private final static byte KeyByteArray3DES[] = {
(byte)0x47, (byte)0x00, (byte)0x54, (byte)0xb5,
(byte)0x8c, (byte)0x5f, (byte)0x38, (byte)0x45,
(byte)0xbc, (byte)0xf2, (byte)0xa3, (byte)0x45,
(byte)0x85, (byte)0xd4, (byte)0x63, (byte)0x63,
(byte)0x24, (byte)0x2f, (byte)0xfc, (byte)0xe3,
(byte)0x2d, (byte)0x3d, (byte)0x5f, (byte)0x01
};
public static void main(String args[]) {
try {
Security.addProvider(new com.sun.crypto.provider.SunJCE());
// generate key
DESedeKeySpec desedeKeySpec = new DESedeKeySpec (KeyByteArray3DES);
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DESede");
SecretKey key = keyFactory.generateSecret(desedeKeySpec);
Cipher cip = Cipher.getInstance("DESede");
cip.init(Cipher.DECRYPT_MODE, key);
FileInputStream fis = new FileInputStream("NVGenc.txt");
CipherInputStream cis = new CipherInputStream(fis, cip);
BufferedInputStream bis = new BufferedInputStream(cis);
FileOutputStream fos = new FileOutputStream("dec_out.txt");
byte[] b = new byte[1024];
int i = bis.read(b);
while (i != -1)
{
fos.write(b, 0, i);
System.out.println(i);
i = cis.read(b);
}
fos.close();
cis.close();
cis.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
--------
I wrote a class in java for enyrypting a file longer then 8 characters.
This file can be decrypted with the code above. Only by encrypting with openssl this error occurs.
Is the anybody who had the same problem or knows the answer.
THX,
Robert