fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.security.*;
  7. import javax.crypto.spec.SecretKeySpec;
  8. import javax.crypto.Cipher;
  9.  
  10. /* Name of the class has to be "Main" only if the class is public. */
  11. class Ideone
  12. {
  13. public static void main (String[] args) throws java.lang.Exception
  14. {
  15. String key = "Bar12345Bar12345"; // 128 bit key
  16. String text = "Bar12345Bar12345"; // 128 bit key
  17. // Create key and cipher
  18. Key aesKey = new SecretKeySpec(key.getBytes(), "AES");
  19. Cipher cipher = Cipher.getInstance("AES");
  20. // encrypt the text
  21. cipher.init(Cipher.ENCRYPT_MODE, aesKey);
  22. byte[] encrypted = cipher.doFinal(text.getBytes());
  23. String e=new String(encrypted);
  24. byte[] encrypted1 = cipher.doFinal(e.getBytes());
  25. System.out.println(encrypted.length+" "+encrypted1.length);
  26. System.out.println(e);
  27. // decrypt the text
  28. cipher.init(Cipher.DECRYPT_MODE, aesKey);
  29. String decrypted = new String(cipher.doFinal(encrypted));
  30. System.out.println(decrypted);
  31. }
  32. }
Success #stdin #stdout 0.62s 321984KB
stdin
Standard input is empty
stdout
32 64
t�ᩘ�S�6� nK˂�I��c�=���2
Bar12345Bar12345