Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  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. */
  6. package ehabshhadat;
  7.  
  8. import java.io.FileInputStream;
  9. import java.io.FileNotFoundException;
  10. import java.io.FileOutputStream;
  11. import java.io.IOException;
  12. import java.security.InvalidKeyException;
  13. import java.security.NoSuchAlgorithmException;
  14. import java.security.spec.InvalidKeySpecException;
  15. import javax.crypto.Cipher;
  16. import javax.crypto.CipherInputStream;
  17. import javax.crypto.NoSuchPaddingException;
  18. import javax.crypto.SecretKey;
  19. import javax.crypto.SecretKeyFactory;
  20. import javax.crypto.spec.DESKeySpec;
  21.  
  22. /**
  23. *
  24. * @author cslab3
  25. */
  26. public 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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement