Total members 9952 | Gratitudes |It is currently Sat Feb 11, 2012 3:16 pm Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 1 post ] 
Author Topic
 Topic subject: Data missing when implementing 3DES using DES
PostPosted: Sun Mar 28, 2010 3:16 pm 
Offline
Newbie
User avatar

Joined: Sun Mar 28, 2010 3:08 pm
Posts: 1
Has thanked: 0 time
Have thanks: 0 time

Here is the code:
Code:

import java
.io.*;
import java.security.*;
import javax.crypto.*;

public class 
test {

    public static 
void main(String[] argsthrows Exception
    
{
        
KeyGenerator keyg KeyGenerator.getInstance("DES");
    
SecureRandom random SecureRandom.getInstance("SHA1PRNG");
    
keyg.init(56random);

    
SecretKey sk1 keyg.generateKey();
        
SecretKey sk2 keyg.generateKey();

        
Cipher cp1 Cipher.getInstance("DES");
    
cp1.init(Cipher.ENCRYPT_MODEsk1);

        
Cipher cp2 Cipher.getInstance("DES");
        
cp2.init(Cipher.DECRYPT_MODEsk2);

        
Cipher cp3 Cipher.getInstance("DES");
        
cp3.init(Cipher.ENCRYPT_MODEsk1);

        
FileInputStream fis = new FileInputStream("input.txt");
        
FileOutputStream fos = new FileOutputStream("encrypted.txt");

        
CipherOutputStream cos1 = new CipherOutputStream(foscp1);
        
CipherOutputStream cos2 = new CipherOutputStream(cos1cp2);
        
CipherOutputStream cos3 = new CipherOutputStream(cos2cp3);

        
byte b[] = new byte[8];
        
int i fis.read(b);
        while(
!= -1){
            
cos3.write(b0i);
            
fis.read(b);
        }

        
fis.close();
        
cos3.close();

        
//Decrypt contents from file
        
FileInputStream fiss = new FileInputStream("encrypted.txt");
        
FileOutputStream foss = new FileOutputStream("original.txt");
        
cp1.init(Cipher.DECRYPT_MODEsk1);
        
cp2.init(Cipher.ENCRYPT_MODEsk2);
        
cp3.init(Cipher.DECRYPT_MODEsk1);

        
CipherInputStream cis1 = new CipherInputStream(fisscp1);
        
CipherInputStream cis2 = new CipherInputStream(cis1cp2);
        
CipherInputStream cis3 = new CipherInputStream(cis2cp3);

        
cis3.read(b);
        while(
!= -1){
            
foss.write(b0i);
            
cis3.read(b);
        }

        
cis3.close();
        
foss.close();
    }
}
 

And this is the input.txt file:
This is the content of the message. Let's see what happen at the end

When I run this code, the original file is:
This is the content of the message. Let's see what happen at the

-> So the "end" word is missing. I don't know what has happened.

But when the input.txt file is:
This is the content of the message. Let's see what happen at the

Then the original.txt file is:
This is the content of the message. Let's see what happen at the

This time it works.

Can anyone show me why this happened ?? Thanks a lot.


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 1 post ] 
Quick reply


  


 Similar topics
 Topic title   Forum   Author   Comments 
 Data Encryption Standard (DES)  Finished Projects  msi_333  13
 How to make PHP form data saved into txt file  PHP  Radu  6
 charm algorithm in data mining  Java  Anusha123  3
 Des java Applet ( Data Encryption Standards )  Java  msi_333  1
 How to merge the data into file  Java  Anonymous  1

All times are UTC [ DST ]


Users browsing similar posts

Users browsing this forum: No registered users and 4 guests



Jump to:  
Previous Topic | Next Topic 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team