Guest User

Untitled

a guest
Nov 20th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. private void main(String[] args)throws LoginException, NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
  2. String s = "ab";
  3. Cipher cipher = Cipher.getInstance("AES");
  4.  
  5. KeyGenerator kgen = KeyGenerator.getInstance("AES");
  6. kgen.init(128);
  7. SecretKey key = kgen.generateKey();
  8.  
  9.  
  10. cipher.init(Cipher.ENCRYPT_MODE,key);
  11. byte[] bytes = cipher.doFinal(s.getBytes());
  12. for (byte b : bytes){
  13. // time.setText(s+" "+ b);
  14.  
  15. }
  16. // String str = new String(bytes, StandardCharsets.UTF_8);
  17. Cipher decript = Cipher.getInstance("AES");
  18. decript.init(Cipher.DECRYPT_MODE,key);
  19. byte[] decriptedBytes = decript.doFinal(bytes);
  20. for (byte b : decriptedBytes){
  21.  
  22. time.setText(String.valueOf((char) b));
  23. }
  24. }
Add Comment
Please, Sign In to add comment