· 7 years ago · Apr 26, 2018, 12:22 AM
1 private String encrypt(String text) {
2 String secretKey = "dps903HotelBookI"; //secret key must be 16 length
3 SecretKey key;
4 Cipher cipher;
5 byte[] cipherText;
6 String result = "";
7
8 try
9 {
10 // Set the encryptor
11 key = new SecretKeySpec(secretKey.getBytes(), "AES");
12 cipher = Cipher.getInstance("AES/ECB/PKCS5Padding", "SunJCE");
13
14 // Encrypt the text
15 cipher.init(Cipher.ENCRYPT_MODE, key);
16 cipherText = cipher.doFinal(text.getBytes());
17 result = new String(Base64.encode(cipherText));
18 } catch (Throwable t) {
19 t.printStackTrace();
20 }
21
22 return result;
23 }