aspose file tools*
The moose likes Security and the fly likes Decryption DESede doesn't work completely good ??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Security
Bookmark "Decryption DESede doesn Watch "Decryption DESede doesn New topic
Author

Decryption DESede doesn't work completely good ???

Jochen Maes
Greenhorn

Joined: Dec 03, 2002
Posts: 20
hi all,
i'm encrypting and decrypting a file in the same program. But the Decrypted file doesn't appear well some parts are (seemingly still encrypted)
here is the code i use:
System: JDK1.3.1
JCE 1.2.2
Thank you
CODE]
/*
* test.java
*
* Created on 4 december 2002, 14:19
*/
package com.dastt.sejo.denc;
import java.io.*;
import java.util.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import java.security.*;
import java.security.spec.*;
/**
*
* @author U97488
*/
public class test {

/** Creates a new instance of test */
public test() {
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try{
Security.addProvider(new com.sun.crypto.provider.SunJCE());
File in = new File("c:/tmp/test.txt");
File out = new File("c:/tmp/test_encrypted.txt");
Key key=null;
byte b[] = new byte[1024];
try {
String enckey="012345678901234567890123456789012345678901234";
byte[] rawkey = enckey.getBytes();

DESedeKeySpec keyspec = new DESedeKeySpec(rawkey);
SecretKeyFactory keyfactory = SecretKeyFactory.getInstance("DESede");
key = keyfactory.generateSecret(keyspec);

Cipher ci = Cipher.getInstance("DESede/CBC/NoPadding");
byte[] initValue = new byte[8];
//setIV(initValue);
IvParameterSpec ivSpec = new IvParameterSpec(initValue);
AlgorithmParameters algParams = AlgorithmParameters.getInstance("DESede");
algParams.init(ivSpec);
ci.init(ci.ENCRYPT_MODE, key);
CipherInputStream cis = new CipherInputStream((InputStream)new FileInputStream(in), ci);
InputStreamReader isr = new InputStreamReader(cis, "ISO-8859-1");
StringBuffer strbfr = new StringBuffer();
char c[] = new char[1024];
while(isr.read(c)!=-1){
strbfr.append(c);
}
ci.init(ci.DECRYPT_MODE, key, algParams);
CipherOutputStream cos = new CipherOutputStream((OutputStream)new FileOutputStream("c:/tmp/testJoc.txt"), ci);
OutputStreamWriter osr = new OutputStreamWriter(cos, "ISO-8859-1");
osr.write(strbfr.toString());
osr.flush();
osr.close();
cos.close();
cis.close();

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



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

}
[/CODE]
Jochen Maes
Greenhorn

Joined: Dec 03, 2002
Posts: 20
problem solved:

should be
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Decryption DESede doesn't work completely good ???
 
Similar Threads
Overhead IO : The cryptic case of the extra bytes
encrypt data
Triple Des Pin Encryption
encrypt data in database
How/Where to store encryption key?