· 8 years ago · Nov 20, 2017, 03:34 PM
1private 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
22time.setText(String.valueOf((char) b));
23 }
24 }