Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. import javax.crypto.KeyGenerator.*;
  2. import javax.crypto.*;
  3. import java.util.*;
  4. import java.io.*;
  5. import javax.crypto.Cipher.*;
  6. import java.nio.charset.Charset;
  7. import javax.crypto.spec.IvParameterSpec;
  8. public class encrypt{
  9. public static void main(String []args)throws Exception{
  10. KeyGenerator genobj=KeyGenerator.getInstance("DES");
  11. SecretKey symkey=genobj.generateKey();
  12. Scanner s=new Scanner(System.in);
  13. Cipher cipher=Cipher.getInstance("DES/CBC/PKCS5Padding");
  14. cipher.init(Cipher.ENCRYPT_MODE,symkey,new IvParameterSpec(new byte[8]));
  15. while (true){
  16. String test=s.nextLine();
  17. byte[] tmp = test.getBytes(Charset.forName("UTF-8"));
  18. byte[] done=cipher.doFinal(tmp);
  19. String son=new String(done,"UTF-8");
  20. System.out.println(son);
  21. decrypt(done,symkey);
  22. }
  23.  
  24. }
  25. static void decrypt(byte[] don,SecretKey lol)throws Exception{
  26. Cipher cipher2=Cipher.getInstance("DES/CBC/PKCS5Padding");
  27. cipher2.init(Cipher.DECRYPT_MODE,lol,new IvParameterSpec(new byte[8]));
  28. byte[] dec=cipher2.doFinal(don);
  29. String son2=new String(dec,"UTF-8");
  30. System.out.println(son2);
  31.  
  32.  
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement