• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

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
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic