Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package ehabshhadat;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.security.InvalidKeyException;
- import java.security.NoSuchAlgorithmException;
- import java.security.spec.InvalidKeySpecException;
- import javax.crypto.Cipher;
- import javax.crypto.CipherInputStream;
- import javax.crypto.NoSuchPaddingException;
- import javax.crypto.SecretKey;
- import javax.crypto.SecretKeyFactory;
- import javax.crypto.spec.DESKeySpec;
- /**
- *
- * @author cslab3
- */
- public class Ehabshhadat {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) throws FileNotFoundException, InvalidKeyException, NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException, IOException {
- // TODO code application logic here
- FileInputStream fis=new FileInputStream("ehab.txt");
- FileOutputStream fos=new FileOutputStream("we.txt");
- String key=" welcome";
- DESKeySpec des=new DESKeySpec(key.getBytes());
- SecretKeyFactory s= SecretKeyFactory.getInstance("DES");
- SecretKey key1= s.generateSecret(des);
- Cipher c= Cipher.getInstance("DES");
- c.init(Cipher.ENCRYPT_MODE,key1);
- CipherInputStream cin= new CipherInputStream(fis, c);
- while(true)
- {
- int b=cin.read();
- if(b==-1)
- break;
- fos.write(b);
- }
- cin.close();
- fos.close();
- FileInputStream is=new FileInputStream("we.txt");
- FileOutputStream os=new FileOutputStream("ehab1.txt");
- String key2=" welcome";
- DESKeySpec des1=new DESKeySpec(key.getBytes());
- SecretKeyFactory s1= SecretKeyFactory.getInstance("DES");
- SecretKey key3= s.generateSecret(des);
- Cipher c1= Cipher.getInstance("DES");
- c1.init(Cipher.DECRYPT_MODE,key1);
- CipherInputStream cin1= new CipherInputStream(is, c1);
- while(true)
- {
- int b=cin1.read();
- if(b==-1)
- break;
- os.write(b);
- }
- cin1.close();
- os.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement