· 7 years ago · Jul 21, 2018, 01:28 PM
1private byte[] encrypt(String password) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
2 Cipher cipher = Cipher.getInstance("AES");
3 SecretKeySpec secretKey = new SecretKeySpec("dfgkirvbn25685la".getBytes(), "AES");
4 cipher.init(Cipher.ENCRYPT_MODE, secretKey);
5 return cipher.doFinal(password.getBytes());
6}
7
8private String decrypt(PersonEntity pe) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
9 Cipher cipher = Cipher.getInstance("AES");
10 SecretKeySpec secretKey = new SecretKeySpec("dfgkirvbn25685la".getBytes(), "AES");
11 cipher.init(Cipher.DECRYPT_MODE, secretKey);
12 String s = "";
13 byte[] bites = cipher.doFinal(pe.getPassword());
14 for (byte b : bites) {
15 s += (char) b;
16 }
17 return s;
18}