· 8 years ago · Nov 19, 2017, 02:46 PM
1private void main(String[] args)throws LoginException, NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
2 String s = "hello";
3 Cipher cipher = Cipher.getInstance("AES");
4
5 // KeyGenerator kgen = KeyGenerator.getInstance("AES");
6 // kgen.init(128);
7 // SecretKey key = kgen.generateKey();
8 SecretKeySpec key = new SecretKeySpec("bar12345Bar12345".getBytes(),"AES");
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
22time.setText((char) b);
23 }
24 }