· 9 years ago · Oct 27, 2016, 06:52 AM
1
2package javaapplication12;
3
4import java.io.FileInputStream;
5import java.io.FileNotFoundException;
6import java.io.FileOutputStream;
7import java.io.IOException;
8import java.security.InvalidKeyException;
9import java.security.NoSuchAlgorithmException;
10import java.security.spec.InvalidKeySpecException;
11import javax.crypto.Cipher;
12import javax.crypto.CipherInputStream;
13import javax.crypto.NoSuchPaddingException;
14import javax.crypto.SecretKey;
15import javax.crypto.SecretKeyFactory;
16import javax.crypto.spec.DESKeySpec;
17
18
19public class JavaApplication12
20{
21
22 public static void main(String[] args) throws FileNotFoundException, InvalidKeyException, NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException, IOException
23 {
24 FileInputStream in = new FileInputStream ("Hussein.txt");
25
26 FileOutputStream out = new FileOutputStream("007.txt");
27
28 String key = "20122173007";
29
30 DESKeySpec dks = new DESKeySpec (key.getBytes());
31 SecretKeyFactory skey = SecretKeyFactory.getInstance("DES");
32 SecretKey key2 = skey.generateSecret(dks);
33
34 Cipher c = Cipher.getInstance("DES");
35 c.init(Cipher.ENCRYPT_MODE,key2);
36
37 CipherInputStream cin = new CipherInputStream(in, c);
38
39 while (true)
40 {
41 int b = cin.read();
42
43 if (b==-1)break;
44
45 out.write(b);
46
47 }
48
49 out.close();
50 cin.close();
51
52
53
54
55 }
56
57}