· 9 years ago · Oct 27, 2016, 06:56 AM
1/*
2 * To change this license header, choose License Headers in Project Properties.
3 * To change this template file, choose Tools | Templates
4 * and open the template in the editor.
5 */
6package ehabshhadat;
7
8import java.io.FileInputStream;
9import java.io.FileNotFoundException;
10import java.io.FileOutputStream;
11import java.io.IOException;
12import java.security.InvalidKeyException;
13import java.security.NoSuchAlgorithmException;
14import java.security.spec.InvalidKeySpecException;
15import javax.crypto.Cipher;
16import javax.crypto.CipherInputStream;
17import javax.crypto.NoSuchPaddingException;
18import javax.crypto.SecretKey;
19import javax.crypto.SecretKeyFactory;
20import javax.crypto.spec.DESKeySpec;
21
22/**
23 *
24 * @author cslab3
25 */
26public class Ehabshhadat {
27
28 /**
29 * @param args the command line arguments
30 */
31 public static void main(String[] args) throws FileNotFoundException, InvalidKeyException, NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException, IOException {
32 // TODO code application logic here
33
34 FileInputStream fis=new FileInputStream("ehab.txt");
35 FileOutputStream fos=new FileOutputStream("we.txt");
36 String key=" welcome";
37 DESKeySpec des=new DESKeySpec(key.getBytes());
38 SecretKeyFactory s= SecretKeyFactory.getInstance("DES");
39 SecretKey key1= s.generateSecret(des);
40
41
42
43 Cipher c= Cipher.getInstance("DES");
44 c.init(Cipher.ENCRYPT_MODE,key1);
45 CipherInputStream cin= new CipherInputStream(fis, c);
46 while(true)
47 {
48 int b=cin.read();
49 if(b==-1)
50 break;
51 fos.write(b);
52 }
53 cin.close();
54 fos.close();
55
56
57 FileInputStream is=new FileInputStream("we.txt");
58 FileOutputStream os=new FileOutputStream("ehab1.txt");
59
60 String key2=" welcome";
61 DESKeySpec des1=new DESKeySpec(key.getBytes());
62 SecretKeyFactory s1= SecretKeyFactory.getInstance("DES");
63 SecretKey key3= s.generateSecret(des);
64
65
66
67
68 Cipher c1= Cipher.getInstance("DES");
69 c1.init(Cipher.DECRYPT_MODE,key1);
70 CipherInputStream cin1= new CipherInputStream(is, c1);
71 while(true)
72 {
73 int b=cin1.read();
74 if(b==-1)
75 break;
76 os.write(b);
77 }
78 cin1.close();
79 os.close();
80
81
82 }
83
84}