• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Decryption DESede doesn't work completely good ???

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
problem solved:

should be
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic